Jump to content

Recommended Posts

Posted

My file upload script is not working. Can anyone help?

 

This is only part of my script, but I think it's the only part with problems:

 

 

>$uploadDir = '/uploadedfiles/';
$uploadFile = $uploadDir . $_FILES['file']['name'];
if (move_uploaded_file($_FILES['file']['tmp_name'], $uploadFile))
{
   print "File is valid, and was successfully uploaded. ";

}
else
{
   print "There was an error uploading the file.  Please try again.";
    print_r($_FILES);
exit;
}

 

This is the error I get, as well as my programmed error

 

Warning: move_uploaded_file(/uploadedfiles/1210_14_2_web.jpg): failed to open stream: No such file or directory in /home/tcecom/public_html/upload2.php on line 56

 

Isn't this a problem with the server. Do I need to change permissions? Thanks :dance:

Posted

It looks like $uploadDir is set incorrectly. Try this:

>$uploadDir = '/home/your_username_here/public_html/uploadedfiles/';
// Other code unchanged

 

Where your_username_here is your TCH username.

 

With PHP filesystem functions, pathnames are relative to the server root and not your own public_html directory. Your original code is trying to write to a directory just under the server root directory, which presumably doesn't exist (and of course, you wouldn't have permission to access it even if it did exist).

 

Edited to add:

Alternately, you could use a relative path such as

>$uploadDir = 'uploadedfiles/';

 

Note that there is no slash at the beginning of the path. Maybe this is what you meant to do? Since the script is located in your public_html directory, 'uploadedfiles/' points to '/home/your_username_here/public_html/uploadedfiles/'

 

That will work too, but I prefer to use complete path names whenever possible. That way a script doesn't break if you decide to move it to a different directory.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

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