Jump to content

[SOLVED] image replication not working


Ninjakreborn

Recommended Posts

I have a upload script I created, that I replicate to handle images.  It has always worked, this time I replicated it to accept 4 file uploads at one time.

 

however, it's not working.

 

<?php
// get id of property
echo "UPLOAD STATUS"; // name program
// prepare variables
$target = $docroot . "/userimages/"; // prepare target url
$file1 = $_FILES['file1'];
$file2 = $_FILES['file2'];
$file3 = $_FILES['file3'];
$file4 = $_FILES['file4'];
echo "<hr />";
echo "Status on File 1";
echo "<br />";
// query to see if they are at there max image count
$select1 = "SELECT * FROM user_images WHERE userid = '" . $_SESSION['userinfo']['id'] . "';";
$query1 = mysql_query($select1);
if (mysql_num_rows($query1) <= 3) { // run query
if (!empty($file1['name'])) { // check if file was an attempted upload
	$tmp_name1 = $file1['tmp_name'];
	$name1 = $_SESSION['userinfo']['id'] . "_" . $file1['name'];
	$target1 = $target . $name1;
	$i1=@getimagesize($file1['tmp_name']); // get image size
	if (($i1[2]==1) or ($i1[2]==2) or ($i1[2]==3) or ($i1[2]==6)) { // test if proper image type
		if (file_exists($target1)) {
			echo "File 1 is already in the database.<br />";
		}else {
			if (move_uploaded_file($tmp_name1, $target1)) {
				echo "File 1 was moved to temporary memory successfully.<br />";
				$insert = "INSERT INTO user_images(userid, imagename) VALUES('" . 
				$_SESSION['userinfo']['id'] . "', '$name1')";
					if (mysql_query($insert)) {
						echo "File 1 upload successfully completed.<br />";
					}else {
						echo "Problem's inserting it into database though.<br />";
					}
			}else {
				echo "There was a problem uploading this specific file.<br />";
			}
		}
// check for image type
	} else {
	echo "Improper filetype: File discarded.";
	} 
}else {
	echo "You did not attempt to upload File 1, so no actions were performed.<br />";
}
}else {
echo "You have uploaded the max amount of file's you are allowed.<br />";
echo "File 1 upload discarded.<br />";
}

echo "<hr />";
echo "Status on File 2";
echo "<br />";
// Select from db to make sure they have slot's available to upload new images
$select2 = "SELECT * FROM user_images WHERE userid = '" . $_SESSION['userinfo']['id'] . "';";
$query2 = mysql_query($select2);
if (mysql_num_rows($query2) <= 3) {
if (!empty($file2['name'])) {
	$tmp_name2 = $file2['tmp_name'];
	$name2 = $id . "_" . $file2['name'];
	$target2 = $target . $name2;
	$i2=@getimagesize($file2['tmp_name']);
	if (($i2[2]==1) or ($i2[2]==2) or ($i2[2]==3) or ($i2[2]==6)) {
		if (file_exists($target2)) {
			echo "File 2 is already in the database.<br />";
		}else {
			if (move_uploaded_file($tmp_name2, $target2)) {
				echo "File 2 was moved to temporary memory successfully.<br />";
				$insert = "INSERT INTO user_images(userid, imagename) VALUES('" .
				$_SESSION[			'userinfo']['id'] . "', '$name2')";
				if (mysql_query($insert)) {
					echo "File 2 upload successfully completed.<br />";
				}else {
					echo "Problem's inserting it into database though.<br />";
				}
			}else {
				echo "There was a problem uploading this specific file.<br />";
			}
		}
	// check for image type
	} else {
		echo "Improper filetype: File discarded.";
	} 

} else {
	echo "You did not attempt to upload File 2, so no actions were performed.<br />";
}
}else {
echo "You have uploaded the max amount of file's you are allowed.<br />";
echo "File 2 upload discarded.<br />";
}

echo "<hr />";
echo "Status on File 3";
echo "<br />";
// Select from db to make sure they have slot's available to upload new images
$select3 = "SELECT * FROM user_images WHERE userid = '" . $_SESSION['userinfo']['id'] . "';";
$query3 = mysql_query($select3);
if (mysql_num_rows($query3) <= 3) {
if (!empty($file3['name'])) {
	$tmp_name3 = $file3['tmp_name'];
	$name3 = $id . "_" . $file3['tmp_name'];
	$target3 = $target . $name3;
	$i3=@getimagesize($file3['tmp_name']);
	if (($i3[2]==1) or ($i3[2]==2) or ($i3[2]==3) or ($i3[2]==6)) {
		if (file_exists($target3)) {
			echo "File 3 is already in the database.<br />";
		}else {
			if (move_uploaded_file($tmp_name3, $target3)) {
				echo "File 3 was moved to temporary memory successfully.<br />";
				$insert = "INSERT INTO user_images(userid, imagename) VALUES('" . 
				$_SESSION['userinfo']['id'] . "', '$name3')";
					if (mysql_query($insert)) {
						echo "File 3 upload successfully completed.<br />";
					}else {
						echo "Problem's inserting it into database though.<br />";
					}
			}else {
				echo "There was a problem uploading this specific file.<br />";
			}
		}
	// check for image type
	} else {
		echo "Improper filetype: File discarded.";
	} 
} else {
	echo "You did not attempt to upload File 3, so no actions were performed.<br />";
}
}else {
echo "You have uploaded the max amount of file's you are allowed.<br />";
echo "File 3 upload discarded.<br />";
}

echo "<hr />";
echo "Status on File 4";
echo "<br />";
// Select from db to make sure they have slot's available to upload new images
$select4 = "SELECT * FROM user_images WHERE userid = '" . $_SESSION['userinfo']['id'] . "';";
$query4 = mysql_query($select4);
if (mysql_num_rows($query4) <= 3) {
if (!empty($file4['name'])) {
	$tmp_name4 = $file4['tmp_name'];
	$name4 = $id . "_" . $file4['name'];
	$target4 = $target . $name4;
	$i4=@getimagesize($file4['tmp_name']);
	if (($i4[2]==1) or ($i4[2]==2) or ($i4[2]==3) or ($i4[2]==6)) {
		if (file_exists($target4)) {
			echo "File 4 is already in the database.<br />";
		}else {
			if (move_uploaded_file($tmp_name4, $target4)) {
				echo "File 4 was moved to temporary memory successfully.<br />";
				$insert = "INSERT INTO user_images(userid, imagename) VALUES('" . 
				$_SESSION['userinfo']['id'] . "', '$name4')";
				if (mysql_query($insert)) {
					echo "File 4 upload successfully completed.<br />";
				}else {
					echo "Problem's inserting it into database though.<br />";
				}
			}else {
				echo "There was a problem uploading this specific file.<br />";
			}
		}
	// check for image type
	} else {
		echo "Improper filetype: File discarded.";
	} 
} else {
	echo "You did not attempt to upload File 4, so no actions were performed.<br />";
}
}else {
echo "You have uploaded the max amount of file's you are allowed.<br />";
echo "File 4 upload discarded.<br />";
}

?>

File 1, File 2, and File 4 are all working correctly.  However, anything that get's loaded into the slow for File 3 give's me the following error

Status on File 3

 

Warning: move_uploaded_file(C:/xxamp/xampp/htdocs/########/userimages/_C:\xxamp\xampp\tmp\php25.tmp) [function.move-uploaded-file]: failed to open stream: Invalid argument in C:\xxamp\xampp\htdocs\######\myimages2.php on line 177

 

Warning: move_uploaded_file() [function.move-uploaded-file]: Unable to move 'C:\xxamp\xampp\tmp\php25.tmp' to 'C:/xxamp/xampp/htdocs/########/userimages/_C:\xxamp\xampp\tmp\php25.tmp' in C:\xxamp\xampp\htdocs\#####\myimages2.php on line 177

There was a problem uploading this specific file.

What is strange, is again as you can see the file 3 script is a replicate of file 1, file 2, and file 4.  They are all the same script.  However this one happen's to not be working, any advice, would be greatly appreciated?

Thanks.

Link to comment
https://forums.phpfreaks.com/topic/37531-solved-image-replication-not-working/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.