7 Replies - 1299 Views - Last Post: 28 September 2009 - 12:41 PM Rate Topic: -----

#1 coolmac112  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 58
  • Joined: 30-August 09

move_uploaded_file HELP!

Posted 27 September 2009 - 02:39 PM

Hi guys,

i am stuck on trying to upload and display image files...i'm using a very simple, basic script...here's the code;

if(isset($_POST["submit"])){

$name = $_POST["name"];
$photo = $_FILES["photo"]["name"];
define("UPLOAD_PATH","images/");

if(!empty($name) && !empty($photo)){
$dbc = mysqli_connect('localhost','MY USERNAME','PASS','DB') #the details here are correct.
or die("Could not establish connection");

$target = UPLOAD_PATH.$photo;
if(move_uploaded_file($_FILES["photo"]["temp_name"],$target))
echo "success";

$query = "INSERT INTO folder VALUES ('$name','$photo')";
mysqli_query($dbc,$query);

echo "Thanks for adding your photo: ".$photo." $name";
echo "<br /><img src='".UPLOAD_PATH.$photo."' alt='photo'";

mysqli_close($dbc);
$name = "";
$photo = "";
}else{
echo "please add a photo and your name";
}
}

?>

<form action="<?php echo $_SERVER["PHP_SELF"]; ?>" method="post" enctype="multipart/form-data">
<input type="hidden" value="1024000" name="MAX_FILE_SIZE" />
<label for="name">Name</label>
<input type="text" name="name" id="name" /><br />
<label for="upload">Upload</label>
<input type="file" name="photo" id="photo" /><br />
<input type="submit" name="submit" value="Enter" />



I do not know a lot about move_uploaded_file so i hope you can help me in any way you can.

After submission no image is being displayed and but the path to the image is indeed what I want...i believe the error is coming straight from move_uploaded_file...it's not being moved...folder is empty!!

Is This A Good Question/Topic? 0
  • +

Replies To: move_uploaded_file HELP!

#2 Wimpy  Icon User is offline

  • R.I.P. ( Really Intelligent Person, right? )
  • member icon

Reputation: 159
  • View blog
  • Posts: 1,038
  • Joined: 02-May 09

Re: move_uploaded_file HELP!

Posted 27 September 2009 - 03:38 PM

try something like this and see what it tells you (if anything):
$target = UPLOAD_PATH.$photo;
if(is_uploaded_file($_FILES["photo"]["temp_name"]))
{
	if(is_dir(UPLOAD_PATH))
	{
		if(move_uploaded_file($_FILES["photo"]["temp_name"], $target))
		{
			if(is_file($target))
			{
				echo "Success";
			}
			else
			{
				echo "Something went wrong when moving the file";
			}
		}
		else
		{
			echo "Could not move the uploaded file from the temporary directory";
		}		
	}
	else
	{
		echo "The directory does not exist";
	}
}
else
{
	echo "The file was not uploaded";
}
hope you understand where to put it! :)
Was This Post Helpful? 0
  • +
  • -

#3 coolmac112  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 58
  • Joined: 30-August 09

Re: move_uploaded_file HELP!

Posted 27 September 2009 - 03:50 PM

Thanks a lot...It returned:

"The file was not uploaded"

What could be the problem, I wonder...
Was This Post Helpful? 0
  • +
  • -

#4 JackOfAllTrades  Icon User is offline

  • Saucy!
  • member icon

Reputation: 6052
  • View blog
  • Posts: 23,487
  • Joined: 23-August 08

Re: move_uploaded_file HELP!

Posted 27 September 2009 - 04:02 PM

My money's on not having permissions to save into the directory to which you've attempted to upload.
Was This Post Helpful? 0
  • +
  • -

#5 coolmac112  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 58
  • Joined: 30-August 09

Re: move_uploaded_file HELP!

Posted 27 September 2009 - 04:06 PM

I don't see how that can be though! I have all the permissions and I created the folder a few minutes ago.

I am running on Windows by the way, how can verify if i do have the necessary permissions?

Thanks guys for your responses, you're certainly making learning enjoyable.
Was This Post Helpful? 0
  • +
  • -

#6 Wimpy  Icon User is offline

  • R.I.P. ( Really Intelligent Person, right? )
  • member icon

Reputation: 159
  • View blog
  • Posts: 1,038
  • Joined: 02-May 09

Re: move_uploaded_file HELP!

Posted 27 September 2009 - 04:39 PM

The file might be too big, check your php configuration, the default setting is 2mb max size per file and a total of 8mb per request! :) If the image you are trying to upload is larger than that php setting it won't be successfully uploaded!

Have you set up your php installation manually or using some package like wamp or something similar? Find your php.ini-file and search for "upload_max_filesize" and "post_max_size", and see what they are set to, change them to your liking and restart your server or computer and try again. If you can't find the php.ini-file you can create a file like this:
<?php phpinfo(); ?>
and search for the same again, here you can't change them but you can at least see what they are set to. Hope it helps! :)

Quote

I am running on Windows by the way, how can verify if i do have the necessary permissions?
The folder you are trying to upload to is a temporary folder and not a folder you have created yourself, this folder's path might also be found in the php.ini-file (I think), find the folder and see what privileges a simple user has to it and change them to your likings! :)

This post has been edited by Wimpy: 27 September 2009 - 04:42 PM

Was This Post Helpful? 0
  • +
  • -

#7 coolmac112  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 58
  • Joined: 30-August 09

Re: move_uploaded_file HELP!

Posted 28 September 2009 - 12:01 PM

thanks wimpy,

I installed php using xampp so everything was set up automatically.

I checked the php.in for the settings and i do not see how i am failing to upload files here. I am trying to upload very small files, just avatars..

So I haven't been able to smash this bug as of yet...*shakes head in disappointment*
Was This Post Helpful? 0
  • +
  • -

#8 Wimpy  Icon User is offline

  • R.I.P. ( Really Intelligent Person, right? )
  • member icon

Reputation: 159
  • View blog
  • Posts: 1,038
  • Joined: 02-May 09

Re: move_uploaded_file HELP!

Posted 28 September 2009 - 12:41 PM

What did your php.ini file say? :)
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1