Jump to content

File upload problem


KkillgasmM

Recommended Posts

This is driving me crazy! everywhere I seem to look i cant seem to find a straight answer!

 

Im using the following script to upload images into an image gallery:

 

include "conn.php";

		//rename file
		$sql=mysql_query("SELECT num FROM num");
		if(!$sql)
			{	echo mysql_error();
			}

		else {
		$num=mysql_result($sql, 0, 0);
		echo 'num is '.$num.'<p>';
		$num++;
		}

		$target="Images/pics/";
		$target=$target.$num.'.jpg';
		$target=chmod($target, 0777);

		$res=mysql_query("UPDATE num SET num = $num");

		//check dimensions and filetype, 200px and jpg
		$tmpname=$_FILES['file']['tmp_name'];
		$size=getimagesize($tmpname);

		$filetype=$size[2];

		if($filetype!=2)
			{
				echo "<b>ERROR: All images must be a .jpg</b>";
			}


		//transfer file and insert into databases	
		elseif(move_uploaded_file($_FILES['file']['tmp_name'], $target))
			{
				$name=$num;

				$select=$_POST['select'];
				$pic=$_POST['pic'];

				$res=mysql_query("UPDATE gallery SET $pic='$name' WHERE name = '$select'");
				if(!$res)
					{
						echo '<p>'.mysql_error();
					}
				echo mysql_affected_rows($res).'<p>Image '.$name.'.jpg uploaded to '.$select.' '.$pic;

			}

		else
			{
				echo 'error';
			}

 

But it comes up with the error in the else statement.

 

Ive been told that its due to a permissions error, and to chmod the file [or directory?]

 

My attempt at doing this was by inserting this into the script:

			$target="Images/pics/";
		$target=$target.$num.'.jpg';
		$target=chmod($target, 0777);

 

But it still doesnt work! Please help me!!

 

Thanks.

Link to comment
https://forums.phpfreaks.com/topic/53412-file-upload-problem/
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.