Jump to content

[SOLVED] File Upload Script Issue


phpfreaks14

Recommended Posts

Hello Everybody,

 

This is my first post in this forum.

 

I have an issue related to a PHP script I have written to upload a file on the webserver.

 

My script looks like:

 

<?php

 

 

 

if($_POST["upload_file"] == "Upload File")

 

{

 

if(!isset($_FILES) && isset($HTTP_POST_FILES))

$_FILES = $HTTP_POST_FILES;

 

$uploaddir = '/Library/Webserver/Documents/Site/fileupload/uploaded_files/';

$uploadfile = $uploaddir . basename($_FILES['name_of_uploaded_file']['name']);

 

 

if (move_uploaded_file($_FILES['name_of_uploaded_file']['tmp_name'], $uploadfile))

 

{

echo "File is valid, and was successfully uploaded.\n";

}

 

else {

echo "Error in uploading the File\n";

}

 

echo 'Here is some more debugging info:';

print_r($_FILES);

 

}

 

 

?>

 

 

 

 

<html>

 

<body>

 

 

<form method="POST" enctype="multipart/form-data" name="image_upload_form" action="<?php $_SERVER["PHP_SELF"]; ?>">

<p><input type="file" name="name_of_uploaded_file" size="200000"></p>

<p><input type="submit" name="upload_file" value="Upload File"></p>

</form>

 

</body>

</html>

 

 

Now, when I upload the file I get following error:

 

Error in uploading the File Here is some more debugging info:Array ( [name_of_uploaded_file] => Array ( [name] => DSC02548_1A.jpg [type] => image/jpeg [tmp_name] => /private/var/tmp/phpgbRgq8 [error] => 0 => 50502 ) )

 

 

It seems my file is not getting uploaded in the temporary folder.

I have one more problem.

I have changed the temporary file folder location in php.ini to

upload_tmp_dir = /library/WebServer/Documents/temp/

(I have checked this value by phpinfo())

 

Now why am I getting the value of "tmp_name" as "/private/var/tmp/XYZ" and not as "/library/WebServer/Documents/temp/XYZ" ??

 

And why this code is not working?

 

Please help me out.

 

Thank you so much in advance.

Link to comment
https://forums.phpfreaks.com/topic/75595-solved-file-upload-script-issue/
Share on other sites

looking at your code it looks the file is getting uploaded properly there is a problem with your move command

 

could be permission problems etc.

 

Thanks for your kind reply Rajiv.

I restarted my Web Server:

 

$ sudo /usr/sbin/apachectl restart

Password:

/usr/sbin/apachectl restart: httpd restarted

 

Now the upload temp directory has been changed.

But when I upload the file I still get:

 

Error in uploading the File Here is some more debugging info:Array ( [name_of_uploaded_file] => Array ( [name] => DSC02548_1A.jpg [type] => image/jpeg [tmp_name] => /Library/WebServer/Documents/temp/phpukTA2d [error] => 0 => 50502 ) )

 

Could you please throw some more light?

 

Thanks!

looking at your code it looks the file is getting uploaded properly there is a problem with your move command

 

could be permission problems etc.

 

Thanks for your kind reply Rajiv.

I restarted my Web Server:

 

$ sudo /usr/sbin/apachectl restart

Password:

/usr/sbin/apachectl restart: httpd restarted

 

Now the upload temp directory has been changed.

But when I upload the file I still get:

 

Error in uploading the File Here is some more debugging info:Array ( [name_of_uploaded_file] => Array ( [name] => DSC02548_1A.jpg [type] => image/jpeg [tmp_name] => /Library/WebServer/Documents/temp/phpukTA2d [error] => 0 => 50502 ) )

 

Could you please throw some more light?

 

Thanks!

 

 

The issue got resolved.  :)

There was permission issue. The directory in which I wanted to move the file did not have proper permissions.

Now after changing the permission I am able to upload files.

 

Thanks so much for your help!

 

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.