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