Jump to content

Upload File Error


Northern Flame

Recommended Posts

I want users of my website to be able to submit songs or images to me,

so i created an upload form but the script that processes it gives me an

error message,

 

heres the error message

Warning: move_uploaded_file(pending/image/a.JPG): failed to open stream: No such file or directory in /my_path/download/thanks.php on line 19

Warning: move_uploaded_file(): Unable to move '/tmp/phphaMD5R' to 'pending/image/a.JPG' in /my_path/download/thanks.php on line 19

 

Heres the script

 

<?php
$type = $_POST['type'];

if($type == 'song'){
$t_path = 'pending/song/';
}
elseif($type == 'image'){
$t_path = 'pending/image/';
} else{
$t_path = 'pending/';
}


$t_path = $t_path . basename( $_FILES['file']['name']);

include('includes/headernf.php');

echo '<div id=body>';
if(move_uploaded_file($_FILES['file']['tmp_name'], $t_path)){
echo "     The ".$type." ".basename($_FILES['file']['name'])." has been uploaded! 
Thank you for contributing to this site!";
} else{
echo "     Their was an error when uploading your ".$type.". It is 
possible that the file was too big. Please try again or <a href='/contact.php'>
contact us</a>.";
}
echo '</div>';
?>

Link to comment
Share on other sites

this is always seems to be the prob i guess we have to have something like this on top of this board

 

now the prob is that the path is not correct

 

it is stated here No such file or directory in /my_path/download/thanks.php on line 19

 

now echo your path and check if that is really what your trying to access

Link to comment
Share on other sites

ok i guess try this its from w3school very cool and basic

 

<?php
if (($_FILES["file"]["type"] == "image/gif")
|| ($_FILES["file"]["type"] == "image/pjpeg")
&& ($_FILES["file"]["size"] < 20000))
  {
  if ($_FILES["file"]["error"] > 0)
    {
    echo "Return Code: " . $_FILES["file"]["error"] . "<br />";
    }
  else
    {
    echo "Upload: " . $_FILES["file"]["name"] . "<br />";
    echo "Type: " . $_FILES["file"]["type"] . "<br />";
    echo "Size: " . ($_FILES["file"]["size"] / 1024) . " Kb<br />";
    echo "Temp file: " . $_FILES["file"]["tmp_name"] . "<br />";

    if (file_exists("upload/" . $_FILES["file"]["name"]))
      {
      echo $_FILES["file"]["name"] . " already exists. ";
      }
    else
      {
      move_uploaded_file($_FILES["file"]["tmp_name"],
      "upload/" . $_FILES["file"]["name"]);
      echo "Stored in: " . "upload/" . $_FILES["file"]["name"];
      }
    }
  }
else
  {
  echo "Invalid file";
  }

 

it says that the directory does not exist  this means again the path is incorrect

Link to comment
Share on other sites

Check to make sure that your File that is executing the script has the proper permissions and the folder that you are writing the file to has the correct permissions.

 

When I don't have the permissions set correctly or assigned to the wrong group, I often get that error message (or something almost identical to it).

Link to comment
Share on other sites

alright i told me it was uploaded to a temporary folder,

but once again,

error message:

 

Warning: move_uploaded_file(upload/nf.gif): failed to open stream: No such file or directory in /my_path/download/thanks.php on line 25

 

Warning: move_uploaded_file(): Unable to move '/tmp/phpmfDVem' to 'upload/nf.gif' in /my_path/download/thanks.php on line 25

Stored in: pending/nf.gif

 

and it was never stored in the folder "pending/"

Link to comment
Share on other sites

whaosssss!!!!

 

look

move_uploaded_file($_FILES["file"]["tmp_name"],"upload/" . $_FILES["file"]["name"]);

"upload/" is the folder or the dir

$_FILES["file"]["name"] the name of the file you are uploading

 

in your case you dont change this upload/ as your own dir

Link to comment
Share on other sites

When I lower the permissions on the folder that I am writing too, I get errors just like you are showing.

 

Do you have access to your servers shell?

I really think you have a permissions not set correctly on your pending folder.

 

If you have access to a shell, type...

sudo chmod 0777 /FULLPATH/pending/

 

example... my upload folder for my website is located here:

/var/www/upload/

so I would chmod my folder like this...

sudo chmod 0777 /var/www/upload

 

Once you get your permissions fixed and ruled out, then you can tighten your permissions to increase security.

 

* sudo means you are basically running as a super user.

* the chmod part tells the computer you want to change the permissions of the file in regards to  read, write and execute.

* the 0777 basically makes it so that everyone can read/write/execute (full permissions).

* Last but not least you give the file or the folder you want to apply the permissions to.

 

IF YOU DO NOT HAVE SHELL ACCESS TO YOUR SERVER...

You can actually write a PHP script to do this for you.  It goes something like this...

 

Example from http://us3.php.net/chmod

<?php
chmod("/somedir/somefile", 755);   // decimal; probably incorrect
chmod("/somedir/somefile", "u+rwx,go+rx"); // string; incorrect
chmod("/somedir/somefile", 0755);  // octal; correct value of mode
?> 

 

LAST BUT NOT LEAST...

I promise I am almost done...

Here is another great tutorial about creating scripts to upload files.

http://www.tizag.com/phpT/fileupload.php

 

As said in the tutorial, when a file is uploaded to your server... it is there only temporarily until the script finishes executing.  Once the script finishes (which can be just milliseconds to execute) it destroys those temporary files.  This is why when you looked in the folder, you did not see the file.  This is actually why you are 'copying' the temp file, into a different folder.  That way when the script finishes and deletes the temp file, you still have a copy else where :) .

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.