Jump to content

[SOLVED] file upload OK, but can't read.. /tmp is 777


Recommended Posts

Hi there,

I need to upload a file,

so far i can upload it but when i tried to read it there's no file.

Ive checked /tmp's permissions and they're 777 ( drwxrwxrwx.  32 root root )

my php.ini has file_uploads=ON &  upload_temp_dir =/tmp/

Here's my code so far... it Outputs a tmp file  such as /tmp/phpTEq4Ri/logo.jpg, followed by " NO FILE UPLOAD ERROR" and "CANNOT OPEN FILE"

 

<?php
if(isset($_FILES['foto']) && !empty($_FILES['foto']['name'])) {
	$dir = $_FILES['foto']['tmp_name'];
	$file= $_FILES['foto']['name'];
	echo $dir.'/'.$file;

	switch($_FILES['foto']['error']){
		case (0): echo "NO FILE UPLOAD ERROR<br>"; break;	
	}

	if (!@fopen($dir.'/'.$file, "r")) { echo "CANNOT OPEN FILE"; 	$foto="''";	}
	else echo "FILE OPENED";

} else echo "NO FILE UPLOAD";

?>




</html>
<head></head>
<body>
<form name='test' action='fileUp.php' method='post' enctype='multipart/form-data'>
<input type='file' name='foto'>
<input type='submit'>
</form>
</body>
</html>

 

 

Thanks

 

 

 

Sorry, I did not scroll down in the code box.

 

$_FILES["foto"]["tmp_name"] returns the name of the temporary copy of the file stored on the server not the directory

 

AND

 

$_FILES["foto"]["name"] returns the name of the file you uploaded...it is not stored on the server by this name.

 

So, what I would do is :

 

$path="directory/images/".$_FILES['foto']['name'];
move_uploaded_file($_FILES['foto']['tmp_name'], $path);

 

you are getting an error because there is no directory /tmp/phpTEq4Ri

 

and no file logo.jpg

Thanks, it makes sense, still i cant get  move_uploaded_file to return true ...  :facepalm:

 

 

 

<?php
if(isset($_FILES['foto']) && !empty($_FILES['foto']['name'])) {
	$tmp_name = $_FILES['foto']['tmp_name']; // temporary copy
	$file_name= $_FILES['foto']['name']; // uploaded...not stored on the server 

	$full_path="tmp/".$file_name;
	echo "moving ".$tmp_name." to ".$full_path."...";

	$moved_file=move_uploaded_file($tmp_name, $fullpath);

	if (!$moved_file) echo "File could not be moved ";


} else echo "NO FILE UPLOAD";

?>

 

the code above returns : moving /tmp/phpydZ5jQ to tmp/face.jpeg...File could not be moved

 

:)

 

Ok, found the error,

 

you are going to kick yourself :)

 

$full_path="tmp/".$file_name;

 

notice the "$full_path"

 

$moved_file=move_uploaded_file($tmp_name, $fullpath);

 

now notice the "$fullpath"

 

compare  "$full_path" with "$fullpath"  :P

 

 

Actually, I had to look a while too :)

 

Have a good one,

 

Ben

 

oh and check out my website (www.bluebeanstalk.com) and pass the word along

 

 

You're right, i do want to kick myself  :P

fixed $full_path and it still didn't work, then i also changed

$full_path="tmp/".$file_name; to $full_path="/tmp/".$file_name;

(adding "/" ) and that did it !

I'm a happy camper .. Thank you VERY VERY much :)

 

Happy weekend

 

 

 

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.

Guest
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.