Jump to content

Photo upload file size issue?


Recommended Posts

Hey there,

I've been dabbling in PHP/MySQL for quite a few years. You'll have to forgive me, most of what I have learned has been self taught and therefore my programming vocab is very limited.

That being said I've stumbled on a problem that I just can't figure out. I recently followed a tutorial that taught me how to build a fairly effective photo upload/gallery system for my website. It works just fine when dealing with photos of a small size (less than 1MB) but I keep getting an error with photos that are bigger. I have diligently searched through the code and made all the adjustments I can think of in order to allow larger photos to upload but I can't figure it out. So here is the error that I receive when attempting to upload larger photo sizes:

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

ERROR: That image has no dimensions


OK. Now for the code. It's pretty substantial so I'll attempt to just include the relevant part. I have commented the offending 'line 94':


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] > 1000){
		header("location: ../message.php?msg=The demo system allows only 1000 pictures total");
	$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){
		echo "ERROR: That image has no dimensions";

	if($fileSize > 10485760) {
		header("location: ../message.php?msg=ERROR: Your image file was larger than 10mb");
	} 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");
	} else if ($fileErrorMsg == 1) {
		header("location: ../message.php?msg=ERROR: An unknown error occurred");
	$moveResult = move_uploaded_file($fileTmpLoc, "../user/$log_username/$db_file_name");
	if ($moveResult != true) {
		header("location: ../message.php?msg=ERROR: File upload failed");
	$wmax = 8000;
	$hmax = 9000;
	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);
	header("location: ../photos.php?u=$log_username");

Any ideas or help would be greatly appreciated. I've been banging my head on my keyboard for over a week trying to figure this out. Could this be a php.ini issue? Am I doing something wrong with the temp file name?

Thanks in advance for your help!  :confused:

Link to comment
Share on other sites




when there's an upload error (most commonly due to exceeding the upload_max_filesize setting), all the elements of the $_FILES array will be set, though most of them will be empty.


you need to test if the upload worked before you can reference any of the uploaded file information. test if $_FILES["photo"]["error"] is set and is equal (two == comparison) to zero or alternatively you can test if $_FILES["photo"]["error"] is exactly equal (three === comparison) to a zero.

Link to comment
Share on other sites

Hey thanks for your help! Any way you could give me the PHP code I would use to test this and where in the code (above in my original post) I would insert it? Sorry, I'm extremely visual and I get it a lot quicker if I see it.



Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.