We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 46450
    • 8 Posts
    I'm using a media source so my client doesn't have to see my whole file tree.

    Currently I have something like

    /
          files/
                images/
    other stuff/


    in my regular file tree, and in the simplified file tree it looks just like

    images/


    however, I've written a PHP code that automatically detects an image, makes a new folder, and puts 3 resized versions of the original image in that folder.

    Because I am echoing the input "/" that my client inputs, instead of the proper "roots/files/images/", I end up creating folders in my web root when I do not want that.

    Is there a way that I can have my client still able to select from a simplified file tree, but for the image input to output the full absolute path? As a quick fix I can just prepend the missing directories, but I'd like a future proof fix if that's possible.

    This question has been answered by Bruno17. See the first response.

      • 4172
      • 5,888 Posts
      where/how are you using this mediasource?
      If you know the mediasource, before outputtting at frontend, you can auto-add the mediasource-path to the stored filename.
        -------------------------------

        you can buy me a beer, if you like MIGX

        http://webcmsolutions.de/migx.html

        Thanks!
        • 46450
        • 8 Posts
        I'm using the mediasource as an image bin - so when I select a template variable, it outputs the path to text, and then I use that text as a PHP variable.

        I also have these settings:

        If that is what you meant.


        I then call the TV in my template with:

        [[!image? &image=`[[*imageFile1]]`]]
          • 4172
          • 5,888 Posts
          you should also add the path to the baseUrl.

          If you have the mediasource assigned to your TV, then the baseUrl should be added automatically with

          [[*imageFile1]]


          But still not sure, what is not working.
          Whats your snippet - code?
            -------------------------------

            you can buy me a beer, if you like MIGX

            http://webcmsolutions.de/migx.html

            Thanks!
            • 46450
            • 8 Posts
            My snippet looks like this:

            <?php
            $imageregular = 'assets/files/images/' . $image; //the string added to image is the temporary fix
            $closing = $end;
            include 'php/fullimage_auto.php';


            With the PHP include looking like this (I am sorry because this is probably going to look like a mess of unnecessary variable but I'm still a novice at PHP)

            <?php
            
            include('php_image_magician.php'); //including image magician EDIT must be in SAME FOLDER AS THIS FILE
            
            #isolating the filename without the directory folders
            
            
            $imagesize = getimagesize($imageregular); //getting image size of original image
            $nopath_spaces = pathinfo($imageregular, PATHINFO_BASENAME); //getting filename itself - spaces and all
            $nopath = $string = preg_replace('/\s+/', '', $nopath_spaces); //stripping filename of any spaces that will break the image
            $path = pathinfo($imageregular, PATHINFO_DIRNAME) . "/"; //path itself
            
            $savepath = $path . pathinfo($nopath, PATHINFO_FILENAME);   //if designated, this will save in a folder named the same as the original image
            
            
            if (!is_dir($savepath)) // if the name of the file is a not also ALREADY a folder
            {
               mkdir($savepath); //create a new folder 
            } 
             
            $id = uniqid(); //generating unique ID
            
            //creates large image - first checks that default image is not already 1920 x 500.  If it is not, it will resize the file, crop it, and overwrite it.
            
            if (!file_exists($savepath . '/' . 'large' . $nopath))
            {
                $imagelarge = new imageLib($imageregular); 
                    if ($imagesize[0] != 1920 && $imagesize[1] != 500){
                        $imagelarge -> resizeImage(1920, 1080, 'crop');
                        }
                $imagelarge -> saveImage($savepath . '/' . 'large' . $nopath, 60);
            }
            
            if (!file_exists($savepath . '/' . 'small' . $nopath))
            {
            $imagesmall = new imageLib($imageregular); 
            $imagesmall -> resizeImage(1280, 350, 'crop');
            $imagesmall -> saveImage($savepath . '/' . 'small' . $nopath, 60);
            }
            
            
            if (!file_exists($savepath . '/' . 'mobile' . $nopath))
            {
            $imagemobile = new imageLib($imageregular); 
            $imagemobile -> resizeImage(630, 250, 'crop');
            $imagemobile -> saveImage($savepath . '/' . 'mobile' . $nopath, 60);
            }
            
            ?>
            
            
            <script type="text/javascript">
            $(document).ready(function(){
                imagesizer();
            });
                
            $(window).resize(function() {
                imagesizer();       
            });
                             
            function imagesizer(){
                    var width = $(window).width();  //widths are -15px because of the scrollbar
                    if(width<=615){
                         $("#<?php echo $id;?>").css("background-image", "url(<?php echo $savepath . '/' . 'mobile' . $nopath;?>)");
                    }else if(width>=615 && width<1265){
                         $("#<?php echo $id;?>").css("background-image", "url(<?php echo $savepath . '/' . 'small' . $nopath;?>)");
                    }else if(width>1265){
                         $("#<?php echo $id;?>").css("background-image", "url(<?php echo $savepath . '/' . 'large' . $nopath;?>)");
                    }
                }             
            </script>
            
            <div id="<?php echo $id;?>" class="bg">
            
            <?php if (closing == false)
            {
            echo '</div>';
            }
            ?>

            • discuss.answer
              • 4172
              • 5,888 Posts
              what happens, when you put

              'assets/files/images/'

              into the mediasource's baseUrl?
                -------------------------------

                you can buy me a beer, if you like MIGX

                http://webcmsolutions.de/migx.html

                Thanks!
                • 46450
                • 8 Posts
                Hmm, it seems to be doing something - but it's putting in a strange ./ before my filename
                I echoed out what file it's calling and it gave me this:

                /assets/files/images/./headerimage.jpg


                It seems to be something that the TV is prepending


                It does this automatically, but if I delete the ./ it will work. How do I remove this?

                EDIT: Did it with baseUrlRelative to no. Thanks
                  • 4172
                  • 5,888 Posts
                  ok, the filebrowser does add this, when you are at the mediasource's root in some situations.

                  you can remove it in your snippet with

                  $imageregular = str_replace('./','',$image);


                    -------------------------------

                    you can buy me a beer, if you like MIGX

                    http://webcmsolutions.de/migx.html

                    Thanks!