Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    Regular Coder
    Join Date
    Aug 2008
    Posts
    127
    Thanks
    2
    Thanked 0 Times in 0 Posts

    issue with getimagesize

    Hi
    I am having issue with my upload image script below namely the getimagesize()

    I am getting this error

    Warning: getimagesize(party.jpg) [function.getimagesize]: failed to open stream: No such file or directory in C:\wamp\www\test_001\pic.php on line 18

    the image moves and renames but it just doesn't give me the image size warnings as the image is well over the specified size.

    Any help would be appreciated


    PHP Code:
    if ((isset($_POST['action'])) && ($_POST['action'] == "Upload Picture")) {
                
                
    //check to see if the field is empty
                
    if (!isset($_FILES['largelogo'])<1) {
                                        
    $largeerr "No file found";         
                            }
                
    $allowedExtensions = array("jpg","gif","jpeg","JPG","png""JPEG");
                
                
    //get attachment name
                
    $filename basename(stripslashes($_FILES['largelogo']['name']));
                
    //get image size and check
                
                
    list($width$height$type$attr) = getimagesize($_FILES['largelogo']['name']);
                
                if ((
    $width>120) || ($height>60)) {
                            
    $largeerr "Your image was too large actual dimensions were $width x $height. Maximium allowed dimensions are 120x60";
                }           
                
                
    //generate new name for attachment for local storage
                
    $newname md5(date("Y-m-d H:i:s").$filename);
                
    //get extension and add it to new file name.
                
    $extension end(explode(".",$_FILES['largelogo']['name']));
                
    $newname $newname.".".$extension;  
                
    //get file type for mimes store in db
                
    $filetype $_FILES['largelogo']['type'];
                
    //check file uploaded correctly and we have generated a correct filename
                
    if(empty($filename)){
                            
    $largeerr "<p id=\"returnresults\"><font color=\"red\"><strong>The name of the file was not found</strong></font></p>";
                }
                
    //check allowed file type
                
    if(!in_array($extension$allowedExtensions)) {
                            
    $largeerr "<p id=\"returnresults\"><font color=\"red\"><strong>Invalid File Type. Please upload an allowed file type.</strong></font></p>";
                }
                if(empty(
    $err)){
                                        
    $newfile "files/img/".$newname;  
                                        
    $result = @move_uploaded_file($_FILES['largelogo']['tmp_name'], $newfile);
                                                    if(empty(
    $result)){
                                                                
    $largeerr "<p id=\"returnresults\"><font color=\"red\"><strong>There was an error moving the uploaded file</strong></font></p>";
                                                    } else {
                                                                
    $query="INSERT INTO `tbldocuments` (`DocName`,`FileName`,`Extension`,`FileType`,`AddedBy`,`upload_time`, `usertype`) VALUES ('$filename','$newname','$extension','$filetype',".$userdetails[0].", NOW(), '1')";
                                                                
    mysql_query($query) or die(mysql_error());
                                                                                                                        
    $largeerr "<p id=\"returnresults\"><font color=\"red\"><strong>Your document has been successfully uploaded onto the system.</strong></font></p>";
                                                    }
                }           


  • #2
    Super Moderator Inigoesdr's Avatar
    Join Date
    Mar 2007
    Location
    Florida, USA
    Posts
    3,638
    Thanks
    2
    Thanked 404 Times in 396 Posts
    $_FILES['largelogo']['name'] is going to contain the name of the original file. You need to use $_FILES['largelogo']['tmp_name'] or wait until it's moved. See the manual for more information.

  • #3
    Regular Coder
    Join Date
    Aug 2008
    Posts
    127
    Thanks
    2
    Thanked 0 Times in 0 Posts
    star thank you

  • #4
    Regular Coder
    Join Date
    Aug 2008
    Posts
    127
    Thanks
    2
    Thanked 0 Times in 0 Posts
    It is uploading and does not show the error message now but I can still upload images above the sizes I specified?

    Have I missed something?
    Last edited by SteveDD; 11-22-2010 at 07:15 PM.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •