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
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!

Link to comment
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!

 

 

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!

 

Link to comment
Share on other sites

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.