Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 5 of 5
  1. #1
    Regular Coder
    Join Date
    Jan 2005
    Posts
    221
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Question PHP File Upload issues... Server Prob?

    I am attempting to use portablewebap to write an interface for a laptop based picture frame... the following code was supposed to upload an image... however, I'm getting the error:



    Warning: move_uploaded_file(PHP\uploadtemp\phpAF3.tmp) [function.move-uploaded-file]: failed to open stream: No such file or directory in C:\Documents and Settings\Charlie\Desktop\no hassle php\PortableWebAp3.1\PortableWebAp3.1\Program\www\localhost\music\upload.php on line 103

    Warning: move_uploaded_file() [function.move-uploaded-file]: Unable to move 'PHP\uploadtemp\phpAF3.tmp' to 'files/test2.txt' in C:\Documents and Settings\Charlie\Desktop\no hassle php\PortableWebAp3.1\PortableWebAp3.1\Program\www\localhost\music\upload.php on line 103
    error moving file from PHP\uploadtemp\phpAF3.tmp to files/test2.txt

    here's the pertinant code:

    PHP Code:

    $uploadDir 
    "files/";
    $i 1;
    $temp $uploadDir;
    $simplename basename$_FILES['file']['name']);
    while(
    file_exists($uploadDir.$simplename))
    {
       
    $uploadDir $temp.$i;
       
    $i++;
    }
    $uploadFile $uploadDir.$simplename;

    if(
    is_uploaded_file($_FILES['file']['tmp_name']))
    {
    }
    else
    {
       echo 
    "the file was not uploaded correctly, try again";
       exit(
    0);
    }

    if(
    move_uploaded_file($_FILES["file"]["tmp_name"], $uploadFile))
          echo 
    "sucessful upload to $uploadFile";
    else
    {
       echo 
    "error moving file from ".$_FILES["file"]["tmp_name"]." to $uploadFile";
       exit(
    0);


    Is the error with my code, or the server? help?

  • #2
    Senior Coder
    Join Date
    Aug 2005
    Posts
    1,119
    Thanks
    2
    Thanked 1 Time in 1 Post
    one thing i notice is that you are trying to move a file into a text document, you can't do that, but you CAN move it to a folder.

  • #3
    Regular Coder
    Join Date
    Jan 2005
    Posts
    221
    Thanks
    2
    Thanked 0 Times in 0 Posts
    isn't move_uploaded_file supposed to move and rename in one step? I was under the impression that it moved the binary contents of the file to the filename specified

  • #4
    Senior Coder
    Join Date
    Aug 2005
    Posts
    1,119
    Thanks
    2
    Thanked 1 Time in 1 Post
    that is incorrect.

    PHP Code:
    move_uploaded_file string filenamestring destination 
    try using this code, and tell me what happens:

    PHP Code:
    $uploadDir "files/"
    $i 1
    $temp $uploadDir
    $simplename basename$_FILES['file']['name']); 
    while(
    file_exists($uploadDir.$simplename)) 

       
    $uploadDir $temp.$i
       
    $i++; 

    $uploadFile $uploadDir.$simplename

    if(
    is_uploaded_file($_FILES['file']['tmp_name'])) 


    else 

       echo 
    "the file was not uploaded correctly, try again"
       exit(
    0); 


    if(
    move_uploaded_file($_FILES["file"]["tmp_name"], $uploadDir )) 
          echo 
    "sucessful upload to $uploadDir"
    else 

       echo 
    "error moving file from ".$_FILES["file"]["tmp_name"]." to $uploadDir"
       exit(
    0); 


  • #5
    Regular Coder
    Join Date
    Jan 2005
    Posts
    221
    Thanks
    2
    Thanked 0 Times in 0 Posts
    i believe now that my issue was mislableing my file directory.. the code you provided creates a file called files with no extension in the server root... you do need to specify file name and extension... just in an existing folder


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •