1 2 Previous Next 43 Replies Latest reply on Mar 12, 2009 12:47 PM by Albert S.

    Upload Image and Resize

    Albert S.
      Hi,

      I'm trying to use the Upload Image and Resize outside of its box.
      What I am trying to accomplish is that when you upload the one image it creates 3 different sizes based off the one upload. I tried a couple things like creating a 2nd
      new tNG_ImageUpload($tNG); with small adjustments and having it run after the first one. But was getting some errors. Before I go and mess with KT_FileUpload.class.php to much I wanted to get some input from the guru's that know ADDT really well.

      Any thoughts are appreciated.

      Thanks
        • 1. Re: Upload Image and Resize
          Günter Schenk Level 4
          Hi Albert,

          -------
          But was getting some errors
          -------

          and what errors did you get exactly ? This info could possibly help us get a clue.

          Cheers,
          Günter Schenk
          Adobe Community Expert, Dreamweaver
          • 2. Re: Upload Image and Resize
            Albert S. Level 3
            Hi Günter,

            Well the first error was with the unlink in KT_FileUpload.class

            Line 240
            unlink($this->fileInfo['tmp_name']);

            So I commented that line out then got errors

            An error occurred while updating the records. (MUPD_ERROR)
            File upload error: Error uploading file. Error moving uploaded file from temporary folder. (FILE_UPLOAD_ERROR)

            Seems like the class uploads the file, move/renames it then deletes it. So the temp file is not available for the other trigger to create a 2nd file in a different size.
            • 3. Re: Upload Image and Resize
              Albert S. Level 3
              Ok here is the exact error.

              Warning: unlink(C:\wamp\tmp\php4F.tmp) [function.unlink]: No such file or directory in C:\wamp\www\dfa\includes\common\lib\file_upload\KT_FileUpload.class.php on line 240

              Developer Details:
              tNG_multipleUpdate error.
              An error occurred while updating the records. (MUPD_ERROR)
              File upload error: Error uploading file. Error moving uploaded file from temporary folder. (FILE_UPLOAD_ERROR)

              When running these triggers.

              //start Trigger_ImageUpload trigger
              //remove this line if you want to edit the code by hand
              function Trigger_ImageUpload(&$tNG) {
              $uploadObj = new tNG_ImageUpload($tNG);
              $uploadObj->setFormFieldName("Picture");
              $uploadObj->setDbFieldName("Picture");
              $uploadObj->setFolder("../assets/artist/{artistID}/{Medium}/");
              $uploadObj->setResize("true", 1200, 900);
              $uploadObj->setMaxSize(5000);
              $uploadObj->setAllowedExtensions("gif, jpg, jpe, jpeg, png");
              $uploadObj->setRename("custom");
              $uploadObj->setRenameRule("{KT_name}_lg.{KT_ext}");
              return $uploadObj->Execute();
              }
              //end Trigger_ImageUpload trigger

              //start Trigger_ImageUpload trigger
              //remove this line if you want to edit the code by hand
              function Trigger_ImageUpload2(&$tNG) {
              $uploadObj = new tNG_ImageUpload($tNG);
              $uploadObj->setFormFieldName("Picture");
              $uploadObj->setFolder("../assets/artist/{artistID}/{Medium}/");
              $uploadObj->setResize("true", 1200, 900);
              $uploadObj->setMaxSize(5000);
              $uploadObj->setAllowedExtensions("gif, jpg, jpe, jpeg, png");
              $uploadObj->setRename("custom");
              $uploadObj->setRenameRule("{KT_name}_md.{KT_ext}");
              return $uploadObj->Execute();
              }
              //end Trigger_ImageUpload trigger

              $ins_media->registerTrigger("AFTER", "Trigger_ImageUpload", 97);
              $ins_media->registerTrigger("AFTER", "Trigger_ImageUpload2", 98);

              I know I could go the route of just having it make a thumbnail at size while viewing the site. ie: show thumbnail function. A lot of changes will have to be made to the site to support that function so I was seeing if I could try this first.
              • 4. Re: Upload Image and Resize
                Albert S. Level 3
                The first file uploads and resizes fine. The 2nd one does not.
                • 5. Re: Upload Image and Resize
                  Günter Schenk Level 4
                  I´m just stabbing in the dark with this, but -- could it be that the 2nd trigger, which currently gets executed immediately after the first one, just happens to fail because the first one´s array of actions (upload & resize) already reaches several limits defined in php.ini such as the "memory_limit" setting, what - to my understanding - could prevent any following action to be executed ?

                  You might want try with this to check out if it makes a difference: PHP has a function called "sleep" (http://de3.php.net/sleep), which will simply let you define a rest period of variable length between two scripts -- and what *might* make a difference, is adding...

                  sleep(10);

                  ...on line 1 of your second trigger; e.g.

                  sleep(10);
                  $uploadObj = new tNG_ImageUpload($tNG);

                  A number like "10" would be the current sleep´s duration in seconds, means you´ll have to play with that number until you get some result.

                  Cheers,
                  Günter Schenk
                  Adobe Community Expert, Dreamweaver
                  • 6. Re: Upload Image and Resize
                    Albert S. Level 3
                    I think that would be the case if I was uploading two files.

                    Keep in mind this is one upload (one file) with two outputs is my goal.

                    I thinking it
                    Trigger 1
                    Posts the file to the temp folder with temp name ie: php4F.tmp -> Moves to the right folder -> Image sizes and Renames it (not in that exact order).

                    Trigger 2
                    Tries to find the posted file -> doesnt exist anymore -> error.

                    am I totally off base?

                    I did try the sleep(10) and nothing changed.
                    • 7. Re: Upload Image and Resize
                      Albert S. Level 3
                      Well my final goal is one file 3 outputs but first starting with 2. If can get the 2 to work the 3 will just be repeating 2.
                      • 8. Re: Upload Image and Resize
                        Albert S. Level 3
                        In old scripts on this site I used this format
                        several times over. Obviously this is not the whole script.

                        // Create destination file
                        $dest_img = imagecreatetruecolor($destLG_width,$destLG_height);

                        // referens from php.net: bool imagecopyresampled ( resource dst_im, resource src_im, int dstX, int dstY, int srcX, int srcY, int dstW, int dstH, int srcW, int srcH)
                        imagecopyresampled($dest_img, $src_img, 0, 0, 0, 0, $destLG_width, $destLG_height, $src_width, $src_height);

                        // referens from php.net: int imagejpeg ( resource image [, string filename [, int quality]])
                        $fileDestName = $fileName;
                        $fileDestName = str_replace(".","_lg.",$fileDestName);
                        $extensions = array("jpg","jpeg","JPG","JPEG");
                        $fileDestName = str_replace($extensions,"jpg",$fileDestName);
                        $fileDestQuality = 90;
                        $fileDestLoc = $uploaddir.$fileDestName;
                        imagejpeg($dest_img, $fileDestLoc, $fileDestQuality);
                        • 9. Re: Upload Image and Resize
                          Albert S. Level 3
                          Not that the old code really matters. Sorry for posting it.
                          • 10. Re: Upload Image and Resize
                            Günter Schenk Level 4
                            sorry, I gotta have a nap now -- it´s late (early) here in Germany. Will get back to you tommorow.

                            BTW, another possible approach would be to try resizing and "save as..." the uploaded file, and I´m somewhat convinced this should be possible by defining the "logic" in a series of Custom "after" Triggers

                            Cheers,
                            Günter Schenk
                            Adobe Community Expert, Dreamweaver
                            • 11. Re: Upload Image and Resize
                              Albert S. Level 3
                              Hi Günter,

                              I hope you had a good long well deserved nap.
                              I went ahead and created some logic in an after trigger as suggested.

                              I posted the after trigger below, it does exactly what I want but I am having a problem with

                              $uploaddir and $fileTmp_Name

                              Which to be honest is most my problems with ADDT triggers. I don't know how to get the information from the transaction into the trigger.
                              When I add the information statically it works fine.
                              How do I get the information from the transaction?

                              After Trigger:

                              $uploaddir = $_SERVER['DOCUMENT_ROOT']."/assets/artist/{artistID}/{Medium}/";
                              $fileTmp_Name = "picture.jpg";

                              $src_img = imagecreatefromjpeg($fileTmp_Name);

                              list($src_width, $src_height, $src_type, $src_attr) = getimagesize($fileTmp_Name);

                              $destMD_height = 250;
                              $destMD_width = 275;

                              // Image ratio calculations
                              $src_ratio = $src_width/$src_height;
                              $dest_ratio = $destMD_width/$destMD_height;
                              if ($dest_ratio > $src_ratio) {
                              $destMD_height = $destMD_height;
                              $destMD_width = round($destMD_height*$src_ratio,0);
                              } else {
                              $destMD_width = $destMD_width;
                              $destMD_height = round($destMD_width/$src_ratio,0);
                              }

                              // Create destination file
                              $dest_img = imagecreatetruecolor($destMD_width,$destMD_height);

                              // referens from php.net: bool imagecopyresampled ( resource dst_im, resource src_im, int dstX, int dstY, int srcX, int srcY, int dstW, int dstH, int srcW, int srcH)
                              imagecopyresampled($dest_img, $src_img, 0, 0, 0, 0, $destMD_width, $destMD_height, $src_width, $src_height);

                              // referens from php.net: int imagejpeg ( resource image [, string filename [, int quality]])
                              $fileDestName = $fileTmp_Name;
                              $fileDestName = str_replace("_lg.","_md.",$fileDestName);
                              $extensions = array("jpg","jpeg","JPG","JPEG");
                              $fileDestName = str_replace($extensions,"jpg",$fileDestName);
                              $fileDestQuality = 90;
                              $fileDestLoc = $uploaddir.$fileDestName;
                              imagejpeg($dest_img, $fileDestLoc, $fileDestQuality);
                              • 12. Re: Upload Image and Resize
                                Albert S. Level 3
                                I know how to get stuff from the transaction on normal triggers. But not in custom triggers. Like for instance on
                                $uploaddir = $_SERVER['DOCUMENT_ROOT']."/assets/artist/{artistID}/{Medium}/";

                                The {artistID} and {Medium} work fine in the Trigger_ImageUpload
                                But don't pull the right info in the Custom Trigger.
                                • 13. Re: Upload Image and Resize
                                  Günter Schenk Level 4
                                  Hi Albert,

                                  -------
                                  How do I get the information from the transaction?
                                  -------

                                  you can "import" transaction values into Custom Triggers using this syntax:

                                  $tNG->getColumnValue("column_name")

                                  I´d personally first declare custom PHP variables at the very start of the custom trigger which are pointing to the $tNG->getColumnValue variables, example:

                                  $artistID = $tNG->getColumnValue("artistID");
                                  $Medium = $tNG->getColumnValue("Medium");

                                  Subsequently it will be much easier to use those "shortcuts" like this:

                                  $uploaddir = $_SERVER['DOCUMENT_ROOT']."/assets/artist/".$artistID."/".$Medium."/";

                                  Cheers,
                                  Günter Schenk
                                  Adobe Community Expert, Dreamweaver
                                  • 14. Re: Upload Image and Resize
                                    Albert S. Level 3
                                    That's what I needed. Thank you very much. Here is the final Trigger:

                                    function Trigger_Custom(&$tNG) {
                                    //Declare database columns
                                    $artistID = $tNG->getColumnValue("artistID");
                                    $Medium = $tNG->getColumnValue("Medium");
                                    $fileTmp_Name = $tNG->getColumnValue("Picture");
                                    //Declare directory
                                    $uploaddir = "../assets/artist/".$artistID."/".$Medium."/";
                                    $combinedDir = $uploaddir.$fileTmp_Name;
                                    // Create two xtra images from source upload
                                    $src_img = imagecreatefromjpeg($combinedDir);
                                    list($src_width, $src_height, $src_type, $src_attr) = getimagesize($combinedDir);

                                    // Medium Image
                                    //Get image ratio
                                    $image_height = 375;
                                    $image_width = 500;
                                    $imageRatio = getImageRatio($image_height, $image_width, $src_height, $src_width);
                                    // Create destination file
                                    $dest_img = imagecreatetruecolor($imageRatio['width'],$imageRatio['height']);

                                    // referens from php.net: bool imagecopyresampled ( resource dst_im, resource src_im, int dstX, int dstY, int srcX, int srcY, int dstW, int dstH, int srcW, int srcH)
                                    imagecopyresampled($dest_img, $src_img, 0, 0, 0, 0, $imageRatio['width'], $imageRatio['height'], $src_width, $src_height);

                                    // referens from php.net: int imagejpeg ( resource image [, string filename [, int quality]])
                                    $fileDestName = $fileTmp_Name;
                                    $fileDestName = str_replace("_lg.","_md.",$fileDestName);
                                    $extensions = array("jpg","jpeg","JPG","JPEG");
                                    $fileDestName = str_replace($extensions,"jpg",$fileDestName);
                                    $fileDestQuality = 90;
                                    $fileDestLoc = $uploaddir.$fileDestName;
                                    imagejpeg($dest_img, $fileDestLoc, $fileDestQuality);

                                    // Small Image
                                    //Get image ratio
                                    $image_height = 75;
                                    $image_width = 75;
                                    $imageRatio = getImageRatio($image_height, $image_width, $src_height, $src_width);
                                    // Create destination file
                                    $dest_img = imagecreatetruecolor($imageRatio['width'],$imageRatio['height']);

                                    // referens from php.net: bool imagecopyresampled ( resource dst_im, resource src_im, int dstX, int dstY, int srcX, int srcY, int dstW, int dstH, int srcW, int srcH)
                                    imagecopyresampled($dest_img, $src_img, 0, 0, 0, 0, $imageRatio['width'], $imageRatio['height'], $src_width, $src_height);

                                    // referens from php.net: int imagejpeg ( resource image [, string filename [, int quality]])
                                    $fileDestName = $fileTmp_Name;
                                    $fileDestName = str_replace("_lg.","_sm.",$fileDestName);
                                    $extensions = array("jpg","jpeg","JPG","JPEG");
                                    $fileDestName = str_replace($extensions,"jpg",$fileDestName);
                                    $fileDestQuality = 90;
                                    $fileDestLoc = $uploaddir.$fileDestName;
                                    imagejpeg($dest_img, $fileDestLoc, $fileDestQuality);
                                    imagedestroy($dest_img);
                                    }
                                    • 15. Re: Upload Image and Resize
                                      Günter Schenk Level 4
                                      Hi Albert,

                                      this is an excellent example of what folks can achieve with Custom Triggers -- thanks a lot for sharing your solution !

                                      Cheers,
                                      Günter Schenk
                                      Adobe Community Expert, Dreamweaver
                                      • 16. Re: Upload Image and Resize
                                        Albert S. Level 3
                                        No problem. I really like ADDT. It makes life easier for those that build sites in databases. Even if ADDT will be gone in a year or so I will use it for as long as I can. I still have some sites using KTML and MX Kollection. :)
                                        • 17. Re: Upload Image and Resize
                                          Albert S. Level 3
                                          Ok just for xtra credit haha. I made it a little cleaner. It now dumps each image it specific folders (large, med, small). ADDT upload and resize takes care of the first folder. The rest is done thru the custom trigger.

                                          function Trigger_Custom(&$tNG) {
                                          //Declare database columns
                                          $artistID = $tNG->getColumnValue("artistID");
                                          $Medium = $tNG->getColumnValue("Medium");
                                          $fileTmp_Name = $tNG->getColumnValue("Picture");
                                          //Declare directories
                                          $uploaddirLG = "../assets/artist/".$artistID."/".$Medium."/Large/";
                                          $uploaddirMD = "../assets/artist/".$artistID."/".$Medium."/Med/";
                                          $uploaddirSM = "../assets/artist/".$artistID."/".$Medium."/Small/";
                                          $combinedDir = $uploaddirLG.$fileTmp_Name;

                                          // Check xtra directories ie: med, small if exists if not create it.
                                          checkFolder($uploaddirMD);
                                          checkFolder($uploaddirSM);

                                          // Create two xtra images from source upload
                                          $src_img = imagecreatefromjpeg($combinedDir);
                                          list($src_width, $src_height, $src_type, $src_attr) = getimagesize($combinedDir);

                                          // Medium Image
                                          //Get image ratio
                                          $image_height = 375;
                                          $image_width = 500;
                                          $imageRatio = getImageRatio($image_height, $image_width, $src_height, $src_width);
                                          // Create destination file
                                          $dest_img = imagecreatetruecolor($imageRatio['width'],$imageRatio['height']);

                                          // referens from php.net: bool imagecopyresampled ( resource dst_im, resource src_im, int dstX, int dstY, int srcX, int srcY, int dstW, int dstH, int srcW, int srcH)
                                          imagecopyresampled($dest_img, $src_img, 0, 0, 0, 0, $imageRatio['width'], $imageRatio['height'], $src_width, $src_height);

                                          // referens from php.net: int imagejpeg ( resource image [, string filename [, int quality]])
                                          $fileDestName = $fileTmp_Name;
                                          $fileDestQuality = 90;
                                          $fileDestLoc = $uploaddirMD.$fileDestName;
                                          imagejpeg($dest_img, $fileDestLoc, $fileDestQuality);
                                          imagedestroy($dest_img);
                                          // Small Image
                                          //Get image ratio
                                          $image_height = 75;
                                          $image_width = 75;
                                          $imageRatio = getImageRatio($image_height, $image_width, $src_height, $src_width);
                                          // Create destination file
                                          $dest_img = imagecreatetruecolor($imageRatio['width'],$imageRatio['height']);

                                          // referens from php.net: bool imagecopyresampled ( resource dst_im, resource src_im, int dstX, int dstY, int srcX, int srcY, int dstW, int dstH, int srcW, int srcH)
                                          imagecopyresampled($dest_img, $src_img, 0, 0, 0, 0, $imageRatio['width'], $imageRatio['height'], $src_width, $src_height);

                                          // referens from php.net: int imagejpeg ( resource image [, string filename [, int quality]])
                                          $fileDestName = $fileTmp_Name;
                                          $fileDestQuality = 90;
                                          $fileDestLoc = $uploaddirSM.$fileDestName;
                                          imagejpeg($dest_img, $fileDestLoc, $fileDestQuality);
                                          imagedestroy($dest_img);
                                          }
                                          //end Trigger_Custom trigger

                                          ### And here are two extra functions being used within the trigger.

                                          // Image ratio calculations
                                          function getImageRatio($dest_height, $dest_width, $src_height, $src_width) {
                                          $src_ratio = $src_width/$src_height;
                                          $dest_ratio = $dest_width/$dest_height;
                                          if ($dest_ratio > $src_ratio) {
                                          $dest_height = $dest_height;
                                          $dest_width = round($dest_height*$src_ratio,0);
                                          } else {
                                          $dest_width = $dest_width;
                                          $dest_height = round($dest_width/$src_ratio,0);
                                          }
                                          $imageRatio['height'] = $dest_height;
                                          $imageRatio['width'] = $dest_width;
                                          return $imageRatio;
                                          }

                                          // Check xtra directories ie: med, small if exists if not create it.
                                          function checkFolder($folderPath) {
                                          $errObj = new tNG_error('Folder cannot be created.', array(), array());
                                          if(is_dir($folderPath)){
                                          } else {
                                          if(mkdir($folderPath, 0775)) {;
                                          return null;
                                          } else {
                                          return $errObj;
                                          }
                                          }
                                          }

                                          ### And don't forget to add xtra delete triggers.

                                          //start Trigger_FileDelete trigger
                                          //remove this line if you want to edit the code by hand
                                          function Trigger_FileDelete1(&$tNG) {
                                          $deleteObj = new tNG_FileDelete($tNG);
                                          $deleteObj->setFolder("../assets/artist/{artistID}/{Medium}/Large/");
                                          $deleteObj->setDbFieldName("Picture");
                                          return $deleteObj->Execute();
                                          }
                                          //end Trigger_FileDelete trigger

                                          //start Trigger_FileDelete trigger
                                          //remove this line if you want to edit the code by hand
                                          function Trigger_FileDelete2(&$tNG) {
                                          $deleteObj = new tNG_FileDelete($tNG);
                                          $deleteObj->setFolder("../assets/artist/{artistID}/{Medium}/Med/");
                                          $deleteObj->setDbFieldName("Picture");
                                          return $deleteObj->Execute();
                                          }
                                          //end Trigger_FileDelete trigger

                                          //start Trigger_FileDelete trigger
                                          //remove this line if you want to edit the code by hand
                                          function Trigger_FileDelete3(&$tNG) {
                                          $deleteObj = new tNG_FileDelete($tNG);
                                          $deleteObj->setFolder("../assets/artist/{artistID}/{Medium}/Small/");
                                          $deleteObj->setDbFieldName("Picture");
                                          return $deleteObj->Execute();
                                          }
                                          //end Trigger_FileDelete trigger
                                          • 18. Re: Upload Image and Resize
                                            Albert S. Level 3
                                            All this info is void is you decide to use "Show Thumbnail" feature. ROFL
                                            • 19. Re: Upload Image and Resize
                                              mrcharis2003@yahoo.c
                                              Hi there

                                              great work Really goo information i have been ttrying to do this exact thing for ages... but I am no good at coding .... and not to familiar with custom triggers

                                              I am trying to put your code into use .... I am having some problems.....

                                              i started by trying to replace all the values in your code with my own values .... but not going to well .....

                                              I am creating some test pages just to get your code working before I use it in my sites.....

                                              A simple upload page with just a pic_name text field and a pic_pic file field ..... and apply an upload and resize image to the file field ... .store image in my images folder

                                              I would like to apply your code to this page ... to the file field .... I think I can do that.....

                                              And a simple list images page and a detail page

                                              That will use all the three image sizes .... so as to test I have it all working ....

                                              If it's not too much to ask ...... Could you please help me a little ?

                                              Could you please tell me what, exact database table you used to get this code working ....

                                              I figure it has an artist_id field and artist_name and artist_picture fields ....

                                              But could you pleas post your database table sql ?

                                              Then I will use the exact table structure ..... then I would only need to change the image path from "/assets/artist/" to "/images/"

                                              One more thing ...... reading your code it says that it checks to see if there is two extra files for med and small images .... and if not found it creates the necesarry folders........ What do I need to change to make your code create the needed files inside my images file? .... or is it easier for me to just create a Med and Small image file inside my Images folder ....?

                                              ANyway if you could help it would be great ..... once I can get your code working with your exat database table structure i can then understand how it works and modify it to suit my needs .....

                                              By the way......

                                              My ideal table structure would be as follows ...

                                              id_pic
                                              name_pic
                                              main_pic full sized image 600px wide
                                              thumb_pic thumbnail sized 100px wide
                                              tooltip_pic tooltip sized 300px wide
                                              Dateadded_pic to sort images by date added

                                              WOuld this table structure work?

                                              And then all my images stored in my ' images ' folder , with Med and Small images in sub-folders

                                              Anyway

                                              Good work keep it up

                                              Have a great day
                                              • 20. Re: Upload Image and Resize
                                                Albert S. Level 3
                                                Hi,
                                                Yes I can help.

                                                Any database structure will work but the fields I am using are

                                                artistID which is not the main id number for the table but an identifier for the aritist.

                                                Medium for if its an original or print.

                                                Picture for the actual file name.

                                                So to relate to your database you only need to worry about

                                                name_pic = Picture

                                                $fileTmp_Name = $tNG->getColumnValue("Picture");
                                                change to
                                                $fileTmp_Name = $tNG->getColumnValue("name_pic");

                                                I added the folders Large/Med/Small so the file name would stay the same and would only need the 1 field in the database. If you decide you want one field for each file I can help with that. Let me know.

                                                Here is where I declare the folders

                                                $uploaddirLG = "../assets/artist/".$artistID."/".$Medium."/Large/";
                                                $uploaddirMD = "../assets/artist/".$artistID."/".$Medium."/Med/";
                                                $uploaddirSM = "../assets/artist/".$artistID."/".$Medium."/Small/";

                                                then using this function call it creates them if they don't exist.

                                                // Check xtra directories ie: med, small if exists if not create it.
                                                checkFolder($uploaddirMD);
                                                checkFolder($uploaddirSM);

                                                This would go into another file or outside of the trigger.
                                                You could put in the trigger if you so desired but I like to keep my functions in another page that I include to the pages that use the functions

                                                // Check xtra directories ie: med, small if exists if not create it.
                                                function checkFolder($folderPath) {
                                                $errObj = new tNG_error('Folder cannot be created.', array(), array());
                                                if(is_dir($folderPath)){
                                                } else {
                                                if(mkdir($folderPath, 0775)) {;
                                                return null;
                                                } else {
                                                return $errObj;
                                                }
                                                }
                                                }

                                                This is where you set the size for the image

                                                // Medium Image
                                                //Get image ratio
                                                $image_height = 375;
                                                $image_width = 500;

                                                Then is uses this function to calculate the ratio (so you dont end up with skewed images.)

                                                This is the function call in the trigger.

                                                $imageRatio = getImageRatio($image_height, $image_width, $src_height, $src_width);

                                                Then again I have the function in another page, included into this page.

                                                // Image ratio calculations
                                                function getImageRatio($dest_height, $dest_width, $src_height, $src_width) {
                                                $src_ratio = $src_width/$src_height;
                                                $dest_ratio = $dest_width/$dest_height;
                                                if ($dest_ratio > $src_ratio) {
                                                $dest_height = $dest_height;
                                                $dest_width = round($dest_height*$src_ratio,0);
                                                } else {
                                                $dest_width = $dest_width;
                                                $dest_height = round($dest_width/$src_ratio,0);
                                                }
                                                $imageRatio['height'] = $dest_height;
                                                $imageRatio['width'] = $dest_width;
                                                return $imageRatio;
                                                }

                                                Let me know if that explains it better. And feel free to ask away with questions.
                                                • 21. Re: Upload Image and Resize
                                                  Albert S. Level 3
                                                  Originally I did have it create a different name for each image then decided to have it same name different folders. So if you need any of that code...
                                                  • 22. Re: Upload Image and Resize
                                                    Albert S. Level 3
                                                    Here is a quick flow of what this trigger helps accomplish.

                                                    Form -> Uploads image -> updates database (1 field) -> creates two new files from uploaded image.

                                                    I think this is what you want?

                                                    Form -> uploads image -> creates two new files (different names) -> updates database (3 fields)

                                                    If this is the case then we will have to make some changes to the trigger(s).
                                                    • 23. Re: Upload Image and Resize
                                                      Albert S. Level 3
                                                      I created a table based on what you asked. I created a form that only had input for 3 fields, name_pic, main_pic, date. This is what the php code would look like above the form.

                                                      // Load the common classes
                                                      require_once('includes/common/KT_common.php');

                                                      // Load the tNG classes
                                                      require_once('includes/tng/tNG.inc.php');

                                                      // Load the KT_back class
                                                      require_once('includes/nxt/KT_back.php');

                                                      // Make a transaction dispatcher instance
                                                      $tNGs = new tNG_dispatcher("");

                                                      // Xtra Functions
                                                      // Check xtra directories ie: med, small if exists if not create it.
                                                      function checkFolder($folderPath) {
                                                      $errObj = new tNG_error('Folder cannot be created.', array(), array());
                                                      if(is_dir($folderPath)){
                                                      } else {
                                                      if(mkdir($folderPath, 0775)) {;
                                                      return null;
                                                      } else {
                                                      return $errObj;
                                                      }
                                                      }
                                                      }

                                                      // Image ratio calculations
                                                      function getImageRatio($dest_height, $dest_width, $src_height, $src_width) {
                                                      $src_ratio = $src_width/$src_height;
                                                      $dest_ratio = $dest_width/$dest_height;
                                                      if ($dest_ratio > $src_ratio) {
                                                      $dest_height = $dest_height;
                                                      $dest_width = round($dest_height*$src_ratio,0);
                                                      } else {
                                                      $dest_width = $dest_width;
                                                      $dest_height = round($dest_width/$src_ratio,0);
                                                      }
                                                      $imageRatio['height'] = $dest_height;
                                                      $imageRatio['width'] = $dest_width;
                                                      return $imageRatio;
                                                      }
                                                      // End Xtra Functions

                                                      // Make unified connection variable
                                                      $conn_db = new KT_connection($db, $database_db);

                                                      // Start trigger
                                                      $formValidation = new tNG_FormValidation();
                                                      $tNGs->prepareValidation($formValidation);
                                                      // End trigger

                                                      //start Trigger_Custom trigger
                                                      function Trigger_Custom(&$tNG) {
                                                      //Declare database columns
                                                      $fileTmp_Name = $tNG->getColumnValue("main_pic");
                                                      //Declare directories
                                                      $uploaddirLG = "images/Large/";
                                                      $uploaddirMD = "images/Med/";
                                                      $uploaddirSM = "images/Small/";
                                                      $combinedDir = $uploaddirLG.$fileTmp_Name;

                                                      // Check xtra directories ie: med, small if exists if not create it.
                                                      checkFolder($uploaddirMD);
                                                      checkFolder($uploaddirSM);

                                                      // Create two xtra images from source upload
                                                      $src_img = imagecreatefromjpeg($combinedDir);
                                                      list($src_width, $src_height, $src_type, $src_attr) = getimagesize($combinedDir);

                                                      // Medium Image
                                                      //Get image ratio
                                                      $image_height = 375;
                                                      $image_width = 500;
                                                      $imageRatio = getImageRatio($image_height, $image_width, $src_height, $src_width);
                                                      // Create destination file
                                                      $dest_img = imagecreatetruecolor($imageRatio['width'],$imageRatio['height']);

                                                      // referens from php.net: bool imagecopyresampled ( resource dst_im, resource src_im, int dstX, int dstY, int srcX, int srcY, int dstW, int dstH, int srcW, int srcH)
                                                      imagecopyresampled($dest_img, $src_img, 0, 0, 0, 0, $imageRatio['width'], $imageRatio['height'], $src_width, $src_height);

                                                      // referens from php.net: int imagejpeg ( resource image [, string filename [, int quality]])
                                                      $fileDestName = $fileTmp_Name;
                                                      $fileDestQuality = 90;
                                                      $fileDestLoc = $uploaddirMD.$fileDestName;
                                                      imagejpeg($dest_img, $fileDestLoc, $fileDestQuality);
                                                      imagedestroy($dest_img);
                                                      // Small Image
                                                      //Get image ratio
                                                      $image_height = 75;
                                                      $image_width = 75;
                                                      $imageRatio = getImageRatio($image_height, $image_width, $src_height, $src_width);
                                                      // Create destination file
                                                      $dest_img = imagecreatetruecolor($imageRatio['width'],$imageRatio['height']);

                                                      // referens from php.net: bool imagecopyresampled ( resource dst_im, resource src_im, int dstX, int dstY, int srcX, int srcY, int dstW, int dstH, int srcW, int srcH)
                                                      imagecopyresampled($dest_img, $src_img, 0, 0, 0, 0, $imageRatio['width'], $imageRatio['height'], $src_width, $src_height);

                                                      // referens from php.net: int imagejpeg ( resource image [, string filename [, int quality]])
                                                      $fileDestName = $fileTmp_Name;
                                                      $fileDestQuality = 90;
                                                      $fileDestLoc = $uploaddirSM.$fileDestName;
                                                      imagejpeg($dest_img, $fileDestLoc, $fileDestQuality);
                                                      imagedestroy($dest_img);
                                                      }
                                                      //end Trigger_Custom trigger

                                                      //start Trigger_FileDelete trigger
                                                      //remove this line if you want to edit the code by hand
                                                      function Trigger_FileDelete(&$tNG) {
                                                      $deleteObj = new tNG_FileDelete($tNG);
                                                      $deleteObj->setFolder("images/Large/");
                                                      $deleteObj->setDbFieldName("main_pic");
                                                      return $deleteObj->Execute();
                                                      }
                                                      //end Trigger_FileDelete trigger

                                                      //start Trigger_ImageUpload trigger
                                                      //remove this line if you want to edit the code by hand
                                                      function Trigger_ImageUpload(&$tNG) {
                                                      $uploadObj = new tNG_ImageUpload($tNG);
                                                      $uploadObj->setFormFieldName("main_pic");
                                                      $uploadObj->setDbFieldName("main_pic");
                                                      $uploadObj->setFolder("images/Large/");
                                                      $uploadObj->setResize("true", 500, 0);
                                                      $uploadObj->setMaxSize(5000);
                                                      $uploadObj->setAllowedExtensions("gif, jpg, jpe, jpeg, png");
                                                      $uploadObj->setRename("auto");
                                                      return $uploadObj->Execute();
                                                      }
                                                      //end Trigger_ImageUpload trigger

                                                      // Make an insert transaction instance
                                                      $ins_pictable = new tNG_multipleInsert($conn_db);
                                                      $tNGs->addTransaction($ins_pictable);
                                                      // Register triggers
                                                      $ins_pictable->registerTrigger("STARTER", "Trigger_Default_Starter", 1, "POST", "KT_Insert1");
                                                      $ins_pictable->registerTrigger("BEFORE", "Trigger_Default_FormValidation", 10, $formValidation);
                                                      //$ins_pictable->registerTrigger("END", "Trigger_Default_Redirect", 99, "includes/nxt/back.php");
                                                      $ins_pictable->registerTrigger("AFTER", "Trigger_ImageUpload", 97);
                                                      $ins_pictable->registerTrigger("AFTER", "Trigger_Custom", 98);
                                                      // Add columns
                                                      $ins_pictable->setTable("pictable");
                                                      $ins_pictable->addColumn("name_pic", "STRING_TYPE", "POST", "name_pic");
                                                      $ins_pictable->addColumn("main_pic", "FILE_TYPE", "FILES", "main_pic");
                                                      $ins_pictable->addColumn("date_pic", "DATE_TYPE", "POST", "date_pic");
                                                      $ins_pictable->setPrimaryKey("id_pic", "NUMERIC_TYPE");

                                                      // Make an update transaction instance
                                                      $upd_pictable = new tNG_multipleUpdate($conn_db);
                                                      $tNGs->addTransaction($upd_pictable);
                                                      // Register triggers
                                                      $upd_pictable->registerTrigger("STARTER", "Trigger_Default_Starter", 1, "POST", "KT_Update1");
                                                      $upd_pictable->registerTrigger("BEFORE", "Trigger_Default_FormValidation", 10, $formValidation);
                                                      //$upd_pictable->registerTrigger("END", "Trigger_Default_Redirect", 99, "includes/nxt/back.php");
                                                      $upd_pictable->registerTrigger("AFTER", "Trigger_ImageUpload", 97);
                                                      $upd_pictable->registerTrigger("AFTER", "Trigger_Custom", 98);
                                                      // Add columns
                                                      $upd_pictable->setTable("pictable");
                                                      $upd_pictable->addColumn("name_pic", "STRING_TYPE", "POST", "name_pic");
                                                      $upd_pictable->addColumn("main_pic", "FILE_TYPE", "FILES", "main_pic");
                                                      $upd_pictable->addColumn("date_pic", "DATE_TYPE", "POST", "date_pic");
                                                      $upd_pictable->setPrimaryKey("id_pic", "NUMERIC_TYPE", "GET", "id_pic");

                                                      // Make an instance of the transaction object
                                                      $del_pictable = new tNG_multipleDelete($conn_db);
                                                      $tNGs->addTransaction($del_pictable);
                                                      // Register triggers
                                                      $del_pictable->registerTrigger("STARTER", "Trigger_Default_Starter", 1, "POST", "KT_Delete1");
                                                      $del_pictable->registerTrigger("END", "Trigger_Default_Redirect", 99, "includes/nxt/back.php");
                                                      $del_pictable->registerTrigger("AFTER", "Trigger_FileDelete", 98);
                                                      $del_pictable->registerTrigger("AFTER", "Trigger_Custom", 50);
                                                      // Add columns
                                                      $del_pictable->setTable("pictable");
                                                      $del_pictable->setPrimaryKey("id_pic", "NUMERIC_TYPE", "GET", "id_pic");

                                                      // Execute all the registered transactions
                                                      $tNGs->executeTransactions();

                                                      // Get the transaction recordset
                                                      $rspictable = $tNGs->getRecordset("pictable");
                                                      $row_rspictable = mysql_fetch_assoc($rspictable);
                                                      $totalRows_rspictable = mysql_num_rows($rspictable);
                                                      • 24. Re: Upload Image and Resize
                                                        Albert S. Level 3
                                                        I didn't add code for xtra delete triggers and multiple names.
                                                        • 25. Re: Upload Image and Resize
                                                          mrcharis2003@yahoo.c Level 1
                                                          Hi there

                                                          Thank you soo much for writing all that code ...... is exactly what I need .... nearly ....

                                                          Sorry I have not posted back sooner ... been away from my computer for a few days

                                                          except I can't get it to work.......

                                                          Just a couple of questions .....

                                                          I your last post (number 23)you wrote a lot of code ..... Do I only need to cut and past that code into the custom trigger basic tab ??

                                                          I will explain what I have done so far

                                                          First I made a database table with 4 fields
                                                          id_pic name_pic main_pic and dateadded_pic

                                                          I then made three pages
                                                          upload.php admin.php and detail.php

                                                          I inserted a dynamic form on my upload.php page with only two fields Pic Name and Main Pic file field I then applied an upload and resize image behavior to that file field storing the images in my 'image' folder

                                                          I created a custom trigger and cut and pasted the code you wrote
                                                          (in post 23) and then I tested it

                                                          I am not sure if I have done all this correctly ..... but I got this
                                                          errors ....
                                                          Warning: require_once(includes/common/KT_common.php) [function.require-once]: failed to open stream: No such file or directory in /home2/petersch/public_html/albert/albertupload.php on line 26

                                                          Fatal error: require_once() [function.require]: Failed opening required 'includes/common/KT_common.php' (include_path='.:/usr/lib/php:/usr/local/lib/php') in /home2/petersch/public_html/albert/albertupload.php on line 26

                                                          So then I uploaded the includes file and tested again and got the same error

                                                          Am I doing this correctly? .... what am I doing wrong?

                                                          I understand that by using the upload and resize image behavior will create the first image ... in this case the full sized image and then your custom trigger will then resize the image two more times and put those images into two folders ... inside the images folder ... and that it will check to see if the folders exist and will create the folders if they are not found .... and that it will not rename the images .... on ly put them in different folders ...

                                                          My question is .... I like that your code does not rename the two images it resizes ..... good that it means that I only need one image field in my database ..... but.....
                                                          Is it still possible to display those new resized images dynamically ... because when I usually display images dynamically .... I retrieve an image name from the database ....... So on my admin page I would display the thumb and tooltip sized picture and on the detail page I would display the full sized image .... and those three different sized images each have there own database table field .... so that I have three different image choices in my bindings tab .. ...... Does that make sense? hard for me to explain .... but I think I still need to have each image name stored in a separate field

                                                          So how would I achieve this if all three images have the same name ? is it still possible?

                                                          Sorry to bother you with sooo many quesions and I really do appreciate the effort you put in writing that code ..

                                                          I would really like to get it to work ......

                                                          If I can get it all to work.... I will write up how I did it in detailed .... layman's terms .... and post it here.... and how to adapt it to different table structure ...."insert your unique id value here " kind of simple ... step by step instructions ... so that anyone can get it to work and help other people like myself who are very codeally challenged ( = cant code much at all )

                                                          Thanks again

                                                          Have a great day
                                                          • 26. Re: Upload Image and Resize
                                                            Albert S. Level 3
                                                            Good Morning,
                                                            Well first off it looks like perhaps your includes folder resides a few folder up from where your pages are, you may want to adjust that

                                                            // Load the common classes
                                                            require_once('includes/common/KT_common.php');

                                                            // Load the tNG classes
                                                            require_once('includes/tng/tNG.inc.php');

                                                            // Load the KT_back class
                                                            require_once('includes/nxt/KT_back.php');

                                                            So you may need to fix these by adding dot dot slash to these require_once statements or how ever many folders your includes is up from your pages.

                                                            // Load the common classes
                                                            require_once('../../<-- how ever many folders up? includes/common/KT_common.php');

                                                            // Load the tNG classes
                                                            require_once('../../includes/tng/tNG.inc.php');

                                                            // Load the KT_back class
                                                            require_once('../../includes/nxt/KT_back.php');

                                                            Also keep in mind that I pasted all the code above the HTML doc not just the trigger so if you take all my code and put it only in the trigger it will not work. You need to read the //Commenting so you know each section of code. if you only want the trigger grab the trigger and xtra functions only.

                                                            // Xtra Functions
                                                            // Check xtra directories ie: med, small if exists if not create it.
                                                            function checkFolder($folderPath) {
                                                            $errObj = new tNG_error('Folder cannot be created.', array(), array());
                                                            if(is_dir($folderPath)){
                                                            } else {
                                                            if(mkdir($folderPath, 0775)) {;
                                                            return null;
                                                            } else {
                                                            return $errObj;
                                                            }
                                                            }
                                                            }

                                                            // Image ratio calculations
                                                            function getImageRatio($dest_height, $dest_width, $src_height, $src_width) {
                                                            $src_ratio = $src_width/$src_height;
                                                            $dest_ratio = $dest_width/$dest_height;
                                                            if ($dest_ratio > $src_ratio) {
                                                            $dest_height = $dest_height;
                                                            $dest_width = round($dest_height*$src_ratio,0);
                                                            } else {
                                                            $dest_width = $dest_width;
                                                            $dest_height = round($dest_width/$src_ratio,0);
                                                            }
                                                            $imageRatio['height'] = $dest_height;
                                                            $imageRatio['width'] = $dest_width;
                                                            return $imageRatio;
                                                            }
                                                            // End Xtra Functions

                                                            //start Trigger_Custom trigger
                                                            function Trigger_Custom(&$tNG) {
                                                            //Declare database columns
                                                            $fileTmp_Name = $tNG->getColumnValue("main_pic");
                                                            //Declare directories
                                                            $uploaddirLG = "images/Large/";
                                                            $uploaddirMD = "images/Med/";
                                                            $uploaddirSM = "images/Small/";
                                                            $combinedDir = $uploaddirLG.$fileTmp_Name;

                                                            // Check xtra directories ie: med, small if exists if not create it.
                                                            checkFolder($uploaddirMD);
                                                            checkFolder($uploaddirSM);

                                                            // Create two xtra images from source upload
                                                            $src_img = imagecreatefromjpeg($combinedDir);
                                                            list($src_width, $src_height, $src_type, $src_attr) = getimagesize($combinedDir);

                                                            // Medium Image
                                                            //Get image ratio
                                                            $image_height = 375;
                                                            $image_width = 500;
                                                            $imageRatio = getImageRatio($image_height, $image_width, $src_height, $src_width);
                                                            // Create destination file
                                                            $dest_img = imagecreatetruecolor($imageRatio['width'],$imageRatio['height']);

                                                            // referens from php.net: bool imagecopyresampled ( resource dst_im, resource src_im, int dstX, int dstY, int srcX, int srcY, int dstW, int dstH, int srcW, int srcH)
                                                            imagecopyresampled($dest_img, $src_img, 0, 0, 0, 0, $imageRatio['width'], $imageRatio['height'], $src_width, $src_height);

                                                            // referens from php.net: int imagejpeg ( resource image [, string filename [, int quality]])
                                                            $fileDestName = $fileTmp_Name;
                                                            $fileDestQuality = 90;
                                                            $fileDestLoc = $uploaddirMD.$fileDestName;
                                                            imagejpeg($dest_img, $fileDestLoc, $fileDestQuality);
                                                            imagedestroy($dest_img);
                                                            // Small Image
                                                            //Get image ratio
                                                            $image_height = 75;
                                                            $image_width = 75;
                                                            $imageRatio = getImageRatio($image_height, $image_width, $src_height, $src_width);
                                                            // Create destination file
                                                            $dest_img = imagecreatetruecolor($imageRatio['width'],$imageRatio['height']);

                                                            // referens from php.net: bool imagecopyresampled ( resource dst_im, resource src_im, int dstX, int dstY, int srcX, int srcY, int dstW, int dstH, int srcW, int srcH)
                                                            imagecopyresampled($dest_img, $src_img, 0, 0, 0, 0, $imageRatio['width'], $imageRatio['height'], $src_width, $src_height);

                                                            // referens from php.net: int imagejpeg ( resource image [, string filename [, int quality]])
                                                            $fileDestName = $fileTmp_Name;
                                                            $fileDestQuality = 90;
                                                            $fileDestLoc = $uploaddirSM.$fileDestName;
                                                            imagejpeg($dest_img, $fileDestLoc, $fileDestQuality);
                                                            imagedestroy($dest_img);
                                                            }
                                                            //end Trigger_Custom trigger

                                                            Lets see if you can get it working with no errors then will tackle the other issues.
                                                            • 27. Re: Upload Image and Resize
                                                              mrcharis2003@yahoo.c Level 1
                                                              Hi there

                                                              Thanks for your response ......

                                                              You were right ......I got rid of the error ...I was getting by putting the 3 pages I made to use your code in the public_html folder before I had the 3 pages I was working on in a folder inside the public_html folder ....

                                                              And reading your response I understand a little more ... of the code you wrote ....

                                                              I started my upload page again .... i got it 100% working uploading and resizing the image once .... then I looked at the code on my upload page compared to the code you wrote .....

                                                              First I should ask ..... should iuse the code you wrote in post 23 or post 26 they are a little different .... ??

                                                              // Load the common classes
                                                              require_once('includes/common/KT_common.php');

                                                              // Load the tNG classes
                                                              require_once('includes/tng/tNG.inc.php');

                                                              // Load the KT_back class
                                                              require_once('includes/nxt/KT_back.php');

                                                              Was already at the top of the page... So I don;t need to copy that ..... one step forward ......

                                                              So then ..... the next thing is the

                                                              // Xtra Functions (and all the code until the next)

                                                              // End Xtra Functions

                                                              Where Do I past the // Xtra Functions code I figured I should paste it directly below the //Load ..... code
                                                              Is that correct ..?

                                                              I tried pasting all the code at the top of the page ... before or above the DOCTYPE html PUBLIC.......

                                                              Is that correct then I pasted all the code from the 'start trigger' to the 'end trigger' into the custom trigger behavior...

                                                              Anyway I tried a few different ways ....

                                                              Then i now get this error

                                                              Fatal error: Cannot redeclare trigger_custom() (previously declared in /home2/petersch/public_html/albertupload.php:55) in /home2/petersch/public_html/albertupload.php on line 57

                                                              Any idea why?

                                                              I will try to add you code again to a clean ... new ... working upload page and try again.....

                                                              My main question would be ......

                                                              Do I paste the top half of your code up untill or above / before the //start Trigger_Custom trigger ...... exactly as you have written it ...? all above the DOCTYPE html..... ??

                                                              Do I past all the code inside the //start Trigger_Custom trigger below that other code or in the custom trigger behavior ??

                                                              Anyway thanks for any help at all .... I will keep trying to get it to work ..... slowly getting there ...... cant wait till it works ...

                                                              Have a great day

                                                              Thanks again
                                                              • 28. Re: Upload Image and Resize
                                                                Albert S. Level 3
                                                                Hi,

                                                                Here is the whole page so were not going back and forth with placement.

                                                                http://certifiednut.com/addt/picform.txt

                                                                This page works with the DB you created under a file structure of
                                                                picform.php
                                                                images
                                                                includes

                                                                Remember that if your includes folder is several folders up you will need to fix the require_once statements at the top of the page.
                                                                • 29. Re: Upload Image and Resize
                                                                  Albert S. Level 3
                                                                  Note that the trigger must run after the upload which by default a custom trigger will run before.

                                                                  $ins_pictable->registerTrigger("AFTER", "Trigger_Custom", 98);

                                                                  $upd_pictable->registerTrigger("AFTER", "Trigger_Custom", 98);

                                                                  That is something that is easily overlooked.

                                                                  Not sure why you are getting that error I would have to see your code.
                                                                  • 30. Re: Upload Image and Resize
                                                                    mrcharis2003@yahoo.c Level 1
                                                                    Hi there

                                                                    Thanks soooo much again ... I just got your latest post ....

                                                                    i have been trying for the last few hours to get it all to work .... since my last post.... now I am super tired

                                                                    but is starting to make sense more now....

                                                                    I followed through your code and realised you had named your database table called pictable so I created a new database table with the same name and then got a little closer ... had it nearly working .... but not quite

                                                                    Anyway

                                                                    I will get back into it tomorrow ....

                                                                    Thanks again for writing such detailed code ... looks very complicated ... but the more I look at it the more I understand ..... well about 10%

                                                                    Anyway thanks again

                                                                    I will try to get it all working with the exact code from the link you sent.... then go from there

                                                                    Thanks again
                                                                    • 31. Re: Upload Image and Resize
                                                                      Albert S. Level 3
                                                                      Sorry if it has been so hard to get working. Perhaps it's not as straight forward as I thought.
                                                                      I have it working in my nextensio form and it works great. I can upload 5 to 7 images at once and all large/med/small get created for each of the images. I will have to add a little more error checking to the trigger though to make it more bullet proof.
                                                                      • 32. Re: Upload Image and Resize
                                                                        mrcharis2003@yahoo.c Level 1
                                                                        Hi there

                                                                        I started back at it again ......

                                                                        I copied and pasted all the code in your link onto a fresh page and then tested it....,. and ... then I get some errors ...

                                                                        But after a wile I figured out I had to make a new database connection named db as in your code require_once('Connections/db.php'); ?>

                                                                        Then I could get the page to display properly .. BIG STEP FORWARD :-)

                                                                        I then tested out uploading a picture and got the following error ....
                                                                        But after that I went and checked in my host ..... your code had made the two extra folders Med and Small .... it Had uploaded the picture to the Large folder ...... but not to the Med or Small folder ....

                                                                        The error I got is .....

                                                                        Warning: imagejpeg() [function.imagejpeg]: SAFE MODE Restriction in effect. The script whose uid is 33120 is not allowed to access /home2/petersch/public_html/images/Med owned by uid 99 in /home2/petersch/public_html/albertupload.php on line 87

                                                                        Warning: imagejpeg() [function.imagejpeg]: Invalid filename in /home2/petersch/public_html/albertupload.php on line 87

                                                                        Warning: imagejpeg() [function.imagejpeg]: SAFE MODE Restriction in effect. The script whose uid is 33120 is not allowed to access /home2/petersch/public_html/images/Small owned by uid 99 in /home2/petersch/public_html/albertupload.php on line 104

                                                                        Warning: imagejpeg() [function.imagejpeg]: Invalid filename in /home2/petersch/public_html/albertupload.php on line 104

                                                                        1 operation(s) succeeded.

                                                                        I am not sure why ?

                                                                        I looked up safe mode and how to turn it off on google but could not figure it out ...... and I have never got any similar errors with ADDT before

                                                                        Any I deas ...
                                                                        Thanks again

                                                                        getting close now

                                                                        Awesome
                                                                        • 33. Re: Upload Image and Resize
                                                                          Albert S. Level 3
                                                                          Do you have a internal testing server or are you testing on the live host? It's basically a permissions error that is happening. What ownership (chown) do the new folders have? useraccount.useraccount or nobody.nobody?

                                                                          Try creating the Large/Med/Small folders manually thru your ftp then try it again. Is your host using suexec to run php scripts? You may have to use a php wrapper. If you call your host they may help you work thru the permission problem.
                                                                          • 34. Re: Upload Image and Resize
                                                                            Albert S. Level 3
                                                                            I may need to re-write the mkdir code for you to use the ADDT folder creation.
                                                                            • 35. Re: Upload Image and Resize
                                                                              Albert S. Level 3
                                                                              Hi Günter,

                                                                              I have a question to help out Charis. In my code I created a simple mkdir function that checks if the directory exists and creates it if not. For me it works great since I manage my own webserver I can change permissions at will. Charis on the other hand I think does not. I know that the ADDT class for checking and create folders is more elaborate.
                                                                              What code would I use to call that class at will?

                                                                              I was thinking something to the extent of

                                                                              $chkF = new KT_Folder($tNG);
                                                                              $chkF -> checkFolder($uploaddir);

                                                                              But I am not really sure. Could you help out?

                                                                              Thank you.
                                                                              • 36. Re: Upload Image and Resize
                                                                                Günter Schenk Level 4
                                                                                Hi Albert,

                                                                                I´m not sure either, but it seems that ADDT´s function checkFolder($uploaddir) is the ideal "shell" for all this, because this function calls other functions like "new KT_folder" or "createFolder" or "checkRights" anyway

                                                                                Here´s what the function description says:

                                                                                Check if the destination folder exists and has write permissions.
                                                                                If the folder does not exists, try to create it.
                                                                                If the folder does not have write permissions or if could not create it, set error

                                                                                -------
                                                                                $chkF -> checkFolder($uploaddir);
                                                                                -------

                                                                                wouldn´t checkFolder($uploaddir); be sufficient in the context of your Custom Trigger ?

                                                                                -------
                                                                                For me it works great since I manage my own webserver I can change permissions at will. Charis on the other hand I think does not
                                                                                -------

                                                                                I wonder if Charis didn´t already stumble across similar issues because of the current safe mode restrictions. ADDT itself checks for this internally (the class KT_shell) and returns a "Error executing command. Safe mode is enabled" message if this is enabled.

                                                                                Let´s ask Charis: have you ever experienced such an issue when using ADDT to upload files into initially non-existing folders, means folders which first have to be created by ADDT prior to uploading stuff into them ?

                                                                                Cheers,
                                                                                Günter Schenk
                                                                                Adobe Community Expert, Dreamweaver
                                                                                • 37. Re: Upload Image and Resize
                                                                                  Albert S. Level 3
                                                                                  Hi Günter,

                                                                                  checkFolder() was a custom function that I wrote. It just happened to have the same name as the function in KT_FileUpload.class.php.
                                                                                  So I read up on using classes, something I did not fully understand on how to use. Now I think I better a better grasp of it. Going forward I will be talking about ADDT's checkFolder();

                                                                                  ---------
                                                                                  wouldn´t checkFolder($uploaddir); be sufficient in the context of your Custom Trigger ?
                                                                                  ---------

                                                                                  Nope!. Regarding ADDT's function. Calling the function out directly doesn't work as the function is tied into a class. So in order to use ADDT's function at will you need to call in the form of a class.
                                                                                  I checked on checkFolder() in KT_FileUpload.class.php and realized it needs all the parameters of the file in order to properly function. So to simplify the issue (I think) I went straight to KT_Folder.class.php where the createFolder function is being held within that class. Then I wrote this code (below) within my customTrigger which accomplishes the task but I am not 100% sure if it tackles all the requirements that Charis needs. We shall see.

                                                                                  New code for customTrigger:

                                                                                  Remove:
                                                                                  checkFolder($uploaddirMD);
                                                                                  checkFolder($uploaddirSM);

                                                                                  Along with the custom function I wrote:
                                                                                  function checkFolder($folderPath) {
                                                                                  $errObj = new tNG_error('Folder cannot be created.', array(), array());
                                                                                  if(is_dir($folderPath)){
                                                                                  } else {
                                                                                  if(mkdir($folderPath, 0775)) {;
                                                                                  return null;
                                                                                  } else {
                                                                                  return $errObj;
                                                                                  }
                                                                                  }
                                                                                  }

                                                                                  And Add:

                                                                                  $chkFolderMD = new KT_Folder();
                                                                                  $chkFolderMD->createFolder($uploaddirMD);
                                                                                  $chkFolderMD->checkRights($uploaddirMD, 'write');

                                                                                  $chkFolderSM = new KT_Folder();
                                                                                  $chkFolderSM->createFolder($uploaddirSM);
                                                                                  $chkFolderSM->checkRights($uploaddirSM, 'write');

                                                                                  Lets see what happens.
                                                                                  • 38. Re: Upload Image and Resize
                                                                                    Albert S. Level 3
                                                                                    Do you think this will work? (last post)
                                                                                    • 39. Re: Upload Image and Resize
                                                                                      mrcharis2003@yahoo.c Level 1
                                                                                      Hi there

                                                                                      Me again sorry to be a pest .... BUT......

                                                                                      I got it working :-)

                                                                                      I read your .... and Gunter's replies ..... and ..... So ....to answer some of your questions ....

                                                                                      I run remotely ...... I also use wamp server to run locally .. but for this I did all remotely ......

                                                                                      I have never had this error when using ADDT.... the closest error I have had from my server is when trying to install Magento ... ecommerce site..... when it returns a SAFE MODE error ... I contacted my host maaaaany times but they still have not fixed it .... more than a month later .....

                                                                                      Also i have never used any code to create folders for me ... to be honest I did not even think it would be possible .... makes me think of maaaany new and interesting possibilities .... thanks for the inspiration ......

                                                                                      Now how did I get it to work ..... first I checked on my host ... like i did say ... when I tried to up load a pic the code you ( Albert) wrote DID create the folders ... and did insert one picture in the Large folder.....(the only folder that I created before) .... So I went back and tried to reset permissions on all the folders under the image folder ..... i had done it before but I checked again and noticed .... that some strange things happening .....

                                                                                      I could not change permissions on the two folders Med and Small that were created be the code you (Albert) wrote..... and I could not delete the folders either ... or the large folder.... So I went up and deleted the whole image folder ..... then I created a new image folder ...and a Large Med and Small sub folders ....

                                                                                      And tried again to upload a picture ...... and it worked ..... Strange hey?

                                                                                      But at least it worked ....

                                                                                      So...... thanks soooo much for all your help has been a real struggle to get working ..... all due to my lack of knowledge ... thanks for all your follow up help ........

                                                                                      Now..... I was a little confused about how to display the images ... but was easy ..... just choose a different image location folder and use the same recordset name_pic field ..... that field stays the same no matter which of the three folders you choos ... VERY cool

                                                                                      So I have got it all up and running ...... I really have to thank you VERY VERY VEEEEEEEEERY much ...... i really have been having problems with displaying any thumbnail at all now I can display three images from one file upload field ...... ABSOLUTELY WONDERFUL STUFF

                                                                                      Thanks again ..... I am sorry to fill this post up with sooo many questions .... I just really wanted to get this to work ....

                                                                                      i will post one more ..... and explain how I did it in detail for anyone else who is having problems ..... I will use the code you supplied .... and reference back to previous posts for any other info......

                                                                                      Thanks again
                                                                                      1 2 Previous Next