www.webdeveloper.com
Results 1 to 6 of 6

Thread: [RESOLVED] HELP! getimagesize() warning - filename cannot be empty

Hybrid View

  1. #1
    Join Date
    Jul 2013
    Posts
    12

    resolved [RESOLVED] HELP! getimagesize() warning - filename cannot be empty

    Please forgive me. I'm kind of a beginner when it comes to this stuff. So, I built a photo upload script using PHP/MySQL. Within the script photos are re-sized and given a temporary name while being uploaded.

    I initially tested the script using several pictures (file size 220 KB | 960 x 720) everything worked just fine. Then I attempted to upload several pictures from my digital camera (file size 2.47 MB | 3000 x 4000) and all of a sudden I got this error:

    Warning: getimagesize() [function.getimagesize]: Filename cannot be empty in /php_parsers/photo_system.php on line 94

    Warning: Cannot modify header information - headers already sent by (output started at /php_parsers/photo_system.php:94) in /php_parsers/photo_system.php on line 96


    I checked other posts to see if there is already a resolution posted in these forums but could never find a scenario where the file upload would work for some files but not others. Anyway, here is the code I'm working with. I've commented the offending line 94 and 96. Any help you could give would be greatly appreciated!

    Code:
    <?php 
    if (isset($_FILES["photo"]["name"]) && isset($_POST["gallery"])){
    	$sql = "SELECT COUNT(id) FROM photos WHERE user='$log_username'";
    	$query = mysqli_query($db_conx, $sql);
    	$row = mysqli_fetch_row($query);
    	if($row[0] > 79){
    		header("location: ../message.php?msg=The system allows only 80 pictures total");
            exit();	
    	}
    	$gallery = preg_replace('#[^a-z 0-9,]#i', '', $_POST["gallery"]);
    	$fileName = $_FILES["photo"]["name"];
            $fileTmpLoc = $_FILES["photo"]["tmp_name"];
    	$fileType = $_FILES["photo"]["type"];
    	$fileSize = $_FILES["photo"]["size"];
    	$fileErrorMsg = $_FILES["photo"]["error"];
    	$kaboom = explode(".", $fileName);
    	$fileExt = end($kaboom);
    	$db_file_name = date("DMjGisY")."".rand(1000,9999).".".$fileExt; // WedFeb272120452013RAND.jpg
    	list($width, $height) = getimagesize($fileTmpLoc); //OFFENDING LINE 94
    	if($width < 10 || $height < 10){
    		header("location: ../message.php?msg=ERROR: That image has no dimensions"); //OFFENDING LINE 96
            exit();	
    	}
    	if($fileSize > 4194304) {
    		header("location: ../message.php?msg=ERROR: Your image file was larger than 4mb");
    		exit();	
    	} else if (!preg_match("/\.(gif|jpg|png)$/i", $fileName) ) {
    		header("location: ../message.php?msg=ERROR: Your image file was not jpg, gif or png type");
    		exit();
    	} else if ($fileErrorMsg == 1) {
    		header("location: ../message.php?msg=ERROR: An unknown error occurred");
    		exit();
    	}
    	$moveResult = move_uploaded_file($fileTmpLoc, "../user/$log_username/$db_file_name");
    	if ($moveResult != true) {
    		header("location: ../message.php?msg=ERROR: File upload failed");
    		exit();
    	}
    	include_once("../php_includes/image_resize.php");
    	$wmax = 800;
    	$hmax = 600;
    	if($width > $wmax || $height > $hmax){
    		$target_file = "../user/$log_username/$db_file_name";
    	    $resized_file = "../user/$log_username/$db_file_name";
    		img_resize($target_file, $resized_file, $wmax, $hmax, $fileExt);
    	}
    	$sql = "INSERT INTO photos(user, gallery, filename, uploaddate) VALUES ('$log_username','$gallery','$db_file_name',now())";
    	$query = mysqli_query($db_conx, $sql);
    	mysqli_close($db_conx);
    	header("location: ../photos.php?u=$log_username");
    	exit();
    }
    ?><?php 
    if (isset($_POST["delete"]) && $_POST["id"] != ""){
    	$id = preg_replace('#[^0-9]#', '', $_POST["id"]);
    	$query = mysqli_query($db_conx, "SELECT user, filename FROM photos WHERE id='$id' LIMIT 1");
    	$row = mysqli_fetch_row($query);
        $user = $row[0];
    	$filename = $row[1];
    	if($user == $log_username){
    		$picurl = "../user/$log_username/$filename"; 
    	    if (file_exists($picurl)) {
    			unlink($picurl);
    			$sql = "DELETE FROM photos WHERE id='$id' LIMIT 1";
    	        $query = mysqli_query($db_conx, $sql);
    		}
    	}
    	mysqli_close($db_conx);
    	echo "deleted_ok";
    	exit();
    }
    ?>
    Please help! I've been trying to figure this out for a week now and to no avail!

  2. #2
    Join Date
    Aug 2004
    Location
    Ankh-Morpork
    Posts
    19,337
    I would guess either a max upload size setting on your web server configuration and/or in your PHP settings (upload_max_filesize). As far as "gracefully" handling the situation in your code, you could start by looking at $_FILES['photo']['error'] to see if it has a non-zero value and proceed from there.
    "Please give us a simple answer, so that we don't have to think, because if we think, we might find answers that don't fit the way we want the world to be."
    ~ Terry Pratchett in Nation

    eBookworm.us

  3. #3
    Join Date
    Jul 2013
    Posts
    12
    Quote Originally Posted by NogDog View Post
    I would guess either a max upload size setting on your web server configuration and/or in your PHP settings (upload_max_filesize). As far as "gracefully" handling the situation in your code, you could start by looking at $_FILES['photo']['error'] to see if it has a non-zero value and proceed from there.
    Hey NogDog. Thanks for looking at this for me. So I checked the error log. I have a TON of this:

    [13-Jul-2013 23:35:29 UTC] PHP Warning: Module 'timezonedb' already loaded in Unknown on line 0

    I verified the time shown is when I attempt to upload the picture file. I'm not sure what this means or if this is even related to my issue but if you have any ideas please let me know!

    Thanks!

  4. #4
    Join Date
    Aug 2004
    Location
    Ankh-Morpork
    Posts
    19,337
    I don't think it's related to your upload issue -- probably worth looking into at some point, though. Looks like you're not the first person to run into it: https://www.google.com/search?q=+Mod...nown+on+line+0
    "Please give us a simple answer, so that we don't have to think, because if we think, we might find answers that don't fit the way we want the world to be."
    ~ Terry Pratchett in Nation

    eBookworm.us

  5. #5
    Join Date
    Jul 2013
    Posts
    12
    Quote Originally Posted by NogDog View Post
    I don't think it's related to your upload issue -- probably worth looking into at some point, though. Looks like you're not the first person to run into it: https://www.google.com/search?q=+Mod...nown+on+line+0
    OK...so here is something more to add to the conundrum. I've been messing with php.ini settings. I noticed that my phpinfo() shows upload_max_filesize 2M. I went into php.ini and added

    Code:
    upload_max_filesize = 250M
    post_max_size = 250M
    However, I was still getting the same error. I tried moving the php.ini file to the actual directory of the offending file but then I was getting a bunch of date() [function.date] errors. However, even though I was getting errors the file made it though. This is some weird stuff. So now I need to solve for the date errors I'm getting:

    Code:
    Warning: date() [function.date]: It is not safe to rely on the system's timezone settings. You are *required* to use the date.timezone setting or the date_default_timezone_set() function. In case you used any of those methods and you are still getting this warning, you most likely misspelled the timezone identifier. We selected 'America/Los_Angeles' for 'PDT/-7.0/DST' instead in /php_parsers/photo_system.php on line 93
    
    Warning: Cannot modify header information - headers already sent by (output started at /php_parsers/photo_system.php:93) in /php_parsers/photo_system.php on line 125

  6. #6
    Join Date
    Jul 2013
    Posts
    12
    Woohoo! Found it! I just added:

    date.timezone = "America/Los_Angeles"

    to the php.ini file that I added to the offending directory and now everything works as it should! NogDog, thanks for talking me through this!

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

Posting Permissions

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



Recent Articles