UPload form doesn't copy images

Discussion in 'Web Design and Development' started by StevenJ, Dec 13, 2009.

  1. StevenJ macrumors newbie

    Joined:
    Dec 13, 2009
    #1
    Hi,

    I am new to Mac. I have done been using the windows IIS development platform for years, but recently bought a mac book and I'm now a complete convert. I have moved my development across to the mac php/mysql and got all that working wonderfully well but my upload form doesn't work.

    I am familiar with unix and I have checked permissions using the shell window and everyone had read/write/execute access in the image folder, but when I try the form and press the upload button, it just doesn't copy the image there.

    Is there anything obvious that I could have missed?

    Kind Regards

    S :confused:
     
  2. jaikob macrumors 6502

    jaikob

    Joined:
    Jul 1, 2008
    Location:
    Freeland, MI
    #2
    You need to post your code.

    Otherwise its a folder permissions problem.

    You did use the move_uploaded_file() function right?

    Use the full path to the images folder starting with root "/" dir.
     
  3. StevenJ thread starter macrumors newbie

    Joined:
    Dec 13, 2009
    #3
    I have checked the folder permissions, and every user has read/write access...

    When the file uploads, it copies the image to the image root folder. From there is should resize the image, and then copy to a sub folder called thumbs, and resize it again. I also have the option of the image being available to a blog, and copy/resize the image a third time.

    Now the image is being copied to the image root folder, but it is not being resized, nor copied to the two sub folders.....

    This DOES work on my windows/apache/php development machine though :mad:

    PHP:
    if ((($_FILES['myfile']['type']) != "image/jpeg" ) &&
                ((
    $_FILES['myfile']['type']) != "image/jpg") &&
                ((
    $_FILES['myfile']['type']) != "image/pjpeg") &&
                ((
    $_FILES['myfile']['type']) != "image/jpe" ))
            {
                
    $result ;
                
    $message $_FILES['myfile']['type'] . "<br />Wrong type of file" ;
                
            } else {         
                if( 
    $_FILES['myfile']['size'] == || $_FILES['orig_file']['size'] > 25360000 ) {
                    
    $result ;
                    
    $message $_FILES['myfile']['size'] . "File is either Zero size or too large" ;
                } else {
                                
                    if (((!
    is_dir($store_dir)) || (!is_dir($thumb_dir)) || (!is_dir($blog_dir)) ) ){
                        
    $result ;
                        
    $message "Destination Specified is not a directory"  ;
                    } else {
                    
                        
    $target_path $store_dir $filename ;
                        
                        if(@
    move_uploaded_file($_FILES['myfile']['tmp_name'], $target_path)) {
                            
    $result 1;
                            
    $message "<br />Filename " $filename ;
                      
                            
    // Max height and width
                            
    $max_width $THUMB_IMAGE_WIDTH ;
                            
    $max_height $THUMB_IMAGE_HEIGHT ;
                            
    $full_max_width $MAIN_IMAGE_WIDTH ;
                            
    $full_max_height $MAIN_IMAGE_HEIGHT ;
                            
    $blog_max_width $BLOG_IMAGE_WIDTH ;
                            
    $blog_max_height $BLOG_IMAGE_HEIGHT ;
                      
                            
    $full $store_dir $filename ;
                            
    $blog $blog_dir $filename ;
                            
    $thumb $thumb_dir $filename ;
                            
                            
    $size GetImageSize($full); // Read the size
                            
    $width $size[0];
                            
    $height $size[1];
                            
                            
    // Proportionally resize the image to the
                            // max sizes specified above
                            
    $x_ratio $max_width $width;
                            
    $y_ratio $max_height $height;
                            
    $full_x_ratio $full_max_width $width;
                            
    $full_y_ratio $full_max_height $height;
                            
    $blog_x_ratio $blog_max_width $width;
                            
    $blog_y_ratio $blog_max_height $height;
                    
                            
    // if necessary resize the uploaded image so that 
                            // the MAX dimension in either direction is not breached.
                             
                            
    if( ($width <= $full_max_width) && ($height <= $full_max_height) )
                            {
                                
    $full_width $width;
                                
    $full_height $height;
                            }
                            elseif ((
    $full_x_ratio $height) < $full_max_height)
                            {
                                
    $full_height ceil($full_x_ratio $height);
                                
    $full_width $full_max_width;
                            }
                            else
                            {
                                
    $full_width ceil($full_y_ratio $width);
                                
    $full_height $full_max_height;
                            }
                            
                            
    // Create the new image!
                            
    $src imagecreatefromjpeg($full);
                            
    $dst imagecreatetruecolor($full_width$full_height);
                            
    imagecopyresampled($dst$src0000$full_width$full_height$width$height);
                            
    imagejpeg($dst$store_dir $filenameIMAGE_QUALITY);
                            
    // Destroy the images
                            // don't destroy the uploaded image until thumbnail has been created/ / ImageDestroy($src);
                            
    imagedestroy($dst);
                            
                            
    // sort out the thumbnail images
                            
    if( ($width <= $max_width) && ($height <= $max_height) )
                            {
                                
    $tn_width $width;
                                
    $tn_height $height;
                            }
                            elseif ((
    $x_ratio $height) < $max_height)
                            {
                                
    $tn_height ceil($x_ratio $height);
                                
    $tn_width $max_width;
                            }
                            else
                            {
                                
    $tn_width ceil($y_ratio $width);
                                
    $tn_height $max_height;
                            }
                    
                            
    $dst imagecreatetruecolor($tn_width$tn_height);
                            
    imagecopyresampled($dst$src0000$tn_width$tn_height$width$height);
                            
    imagejpeg($dst$thumb_dir $filenameIMAGE_QUALITY);
                            
    imagedestroy($dst);

                            
    // sort out the blog images
                            
                            
    if ($_POST['blog'] == 1)  {
                                if( (
    $width <= $blog_max_width) && ($height <= $blog_max_height) )
                                {
                                    
    $blog_width $width;
                                    
    $blog_height $height;
                                }
                                elseif ((
    $blog_x_ratio $height) < $blog_max_height)
                                {
                                    
    $blog_height ceil($blog_x_ratio $height);
                                    
    $blog_width $blog_max_width;
                                }
                                else
                                {
                                    
    $blog_width ceil($blog_y_ratio $width);
                                    
    $blog_height $blog_max_height;
                                }
        
                                
    $dst imagecreatetruecolor($blog_width$blog_height);
                                
    imagecopyresampled($dst$src0000$blog_width$blog_height$width$height);
                                
    imagejpeg($dst$blog_dir $filenameIMAGE_QUALITY);
                                
    imagedestroy($dst);
                            }
                            
                            
    imagedestroy($src);
                            
                    
                    }

                }
            }
        }
     
  4. angelwatt Moderator emeritus

    angelwatt

    Joined:
    Aug 16, 2005
    Location:
    USA
    #4
    PHP:
    imagejpeg($dst$store_dir $filenameIMAGE_QUALITY); 
    Is IMAGE_QUALITY ever defined? Is it a constant or a variable? If a variable, you're missing the $. This variable is used in other parts of the code as well.
     
  5. StevenJ thread starter macrumors newbie

    Joined:
    Dec 13, 2009
    #5
    it is defined. it is defined as a constant 80 in a include file where I have all my constants defined.

    PHP:
    define('IMAGE_QUALITY'80);
     
  6. designguy79 macrumors 6502

    Joined:
    Sep 24, 2009
    Location:
    Michigan
    #6
    I would remove the "@" on this line:

    PHP:
    ...clip... @move_uploaded_file ...clip...
    You are basically suppressing the error handling routine which is keeping you from seeing what the error message is. What is the output with the "@" removed from that line?
     
  7. StevenJ thread starter macrumors newbie

    Joined:
    Dec 13, 2009
    #7
    I am certain I have highlighted the problem....

    I don't have php_gd.dll included.

    I have had a php holiday so to speak, and I think I need it enabled for the following functions, however, I don't know how to do it on a Mac! searhing for the php.ini is more difficult than a PC! I'll master this mac if it kills me, but can anyone advise where I might find the php ini and the php_gd.dll file?


    Code:
    imagecreatefromjpeg()
    imagecreatetruecolor()
    imagecopyresampled()
    imagejpeg()
     
  8. StevenJ thread starter macrumors newbie

    Joined:
    Dec 13, 2009
    #8
    How to install php_gd2.dll?

    the problem is definitely that I have no php_gd2.dll loaded....

    how do I do this? I am new to mac, and hence struggling.

    I have edited the /etc/php.ini file and removed the ';' from the beginning of the line, restarted apache using the terminal - but no extensions show up in phpinfo().

    furthermore, when I navigate to the

    /usr/lib/php/extensions/no-debug-non-zts-20060613

    directory, there are no dll's there :mad:

    how do I enable php_gd2.dll ?
     
  9. angelwatt Moderator emeritus

    angelwatt

    Joined:
    Aug 16, 2005
    Location:
    USA
    #9
    You have to install it if it's not there. If you're not running the server, ask the web host to get it installed.
     
  10. StevenJ thread starter macrumors newbie

    Joined:
    Dec 13, 2009
    #10
    on my host, it's there and my application works grand, it's just on my dev machine which is now a mac, not a PC that I can't get it to work!

    Will look at the instructions you have provided for installation details....
     
  11. designguy79 macrumors 6502

    Joined:
    Sep 24, 2009
    Location:
    Michigan
    #11
    Have you tried MAMP? It comes with gd. I have found it much easier to manage Apache, MySQL, PHP and PhpMyAdmin using 1 package.
     

Share This Page