Jump to content

Basic file upload


millercj

Recommended Posts

Trying to write a basic php file upload script and am getting:

 

Warning: move_uploaded_file() [function.move-uploaded-file]: Unable to move '/tmp/phpI0JnBe' to 'http://www.domain.com/up/filename.jpg' in /home/domain/public_html/up/uploadFile.php on line 14

 

This is my code, I'd assume it is a permissions issue but not sure how to fix that. Any help would be great...

 

<?PHP
echo "<table border=\"1\">";
echo "<tr><td>Client Filename: </td>
   <td>" . $_FILES["fileToUpload"]["name"] . "</td></tr>";
echo "<tr><td>File Type: </td>
   <td>" . $_FILES["fileToUpload"]["type"] . "</td></tr>";
echo "<tr><td>File Size: </td>
   <td>" . ($_FILES["fileToUpload"]["size"] / 1024) . " Kb</td></tr>";
echo "<tr><td>Name of Temporary File: </td>
   <td>" . $_FILES["fileToUpload"]["tmp_name"] . "</td></tr>";
echo "</table>";

move_uploaded_file($_FILES["fileToUpload"]["tmp_name"],
  "http://www.domain.com/up/" . $_FILES["fileToUpload"]["name"]);
?>

Link to comment
https://forums.phpfreaks.com/topic/264351-basic-file-upload/
Share on other sites

You can't use a URL as the target location to move a file too.  You have to use a file system path.  Most likely you will want to use:

 

$_SERVER['DOCUMENT_ROOT'].'/up/'. $_FILES["fileToUpload"]["name"];

 

As your target location to move the file too.  $_SERVER['DOCUMENT_ROOT'] will give you the file system path that corresponds to your domain's directory.  Then you add on the sub path of up/ and the filename.

 

Link to comment
https://forums.phpfreaks.com/topic/264351-basic-file-upload/#findComment-1354706
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.