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

Thread: php upload file

  1. #1
    New Coder
    Join Date
    Nov 2011
    Location
    South Africa
    Posts
    60
    Thanks
    14
    Thanked 0 Times in 0 Posts

    php upload file

    I am trying to include an upload section on my website, once the file is uploaded you should be able to view a list of uploaded files but I keep getting an error:

    Warning: move_uploaded_file(c:/sw/temp/About Stacks.pdf): failed to open stream: No such file or directory in /Applications/XAMPP/xamppfiles/htdocs/upload/uploadfile_action.php on line 14

    Warning: move_uploaded_file(): Unable to move '/Applications/XAMPP/xamppfiles/temp/phpwEOVU4' to 'c:/sw/temp/About Stacks.pdf' in /Applications/XAMPP/xamppfiles/htdocs/upload/uploadfile_action.php on line 14
    FAILED TO UPLOAD About Stacks.pdf
    Temporary Name: /Applications/XAMPP/xamppfiles/temp/phpwEOVU4

    here is my code

    Code:
    <?php
    
    session_start();
    
    include("top.txt");
    ?>
    
    <h3>Upload a file</h3>
    
    <p>You can add files to the system for review by an administrator.
        Click <b>Browse</b> to select the file you'd like to upload,
        and then click <b>Upload</b>.</p>
    
    <form action="uploadfile_action.php" method="POST"
          enctype="multipart/form-data">
        <input type="file" name="ufile" \>
        <input type="submit" value="Upload" \>
    </form>
    
    <?php
       include("bottom.txt");
    ?>
    PHP Code:
    <?php
        session_start
    ();

       include(
    "top.txt");
       include(
    "scripts.txt");

       if(isset(
    $_FILES['ufile']['name'])){
           echo 
    "<p>Uploading: ".$_FILES['ufile']['name']."</p>";

           
    $tmpName $_FILES['ufile']['tmp_name'];
           
    $newName UPLOADEDFILES $_FILES['ufile']['name'];

           if(!
    is_uploaded_file($tmpName) ||
                                !
    move_uploaded_file($tmpName$newName)){
                echo 
    "FAILED TO UPLOAD " $_FILES['ufile']['name'] .
                     
    "<br>Temporary Name: $tmpName <br>";
           } else {

               
    save_document_info_json($_FILES['ufile']);

               echo 
    "<h3>Available Files</h3>";

               
    display_files();
           }

       } else {
         echo 
    "You need to select a file.  Please try again.";
      }
       include(
    "bottom.txt");
    ?>
    can anyone see where I am going wrong?

  • #2
    Master Coder
    Join Date
    Jun 2003
    Location
    Cottage Grove, Minnesota
    Posts
    9,500
    Thanks
    8
    Thanked 1,089 Times in 1,080 Posts
    Is "uploadfile_action.php" in the same directory as the script that shows the form?

    <form action="uploadfile_action.php" method="POST" enctype="multipart/form-data">

    Or should there be a pathname in front of that?

  • #3
    New Coder
    Join Date
    Nov 2011
    Location
    South Africa
    Posts
    60
    Thanks
    14
    Thanked 0 Times in 0 Posts
    its in the same file

  • #4
    Master Coder
    Join Date
    Jun 2003
    Location
    Cottage Grove, Minnesota
    Posts
    9,500
    Thanks
    8
    Thanked 1,089 Times in 1,080 Posts
    1) Make sure this filename is spelled correctly (small letters, caps, underscore?): "uploadfile_action.php

    2) This file: About Stacks.pdf ... try not using a space - rename to: About_Stacks.pdf

  • #5
    Senior Coder CFMaBiSmAd's Avatar
    Join Date
    Oct 2006
    Location
    Denver, Colorado USA
    Posts
    3,044
    Thanks
    2
    Thanked 316 Times in 308 Posts
    Your defined constant UPLOADEDFILES is set to c:/sw/temp/

    That path doesn't exist. You need to set the constant UPLOADEDFILES to be an actual folder where you want the uploaded files to be moved to.
    If you are learning PHP, developing PHP code, or debugging PHP code, do yourself a favor and check your web server log for errors and/or turn on full PHP error reporting in php.ini or in a .htaccess file to get PHP to help you.


  •  

    Tags for this Thread

    Posting Permissions

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