Unable to upload file

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • kailashchandra
    New Member
    • Sep 2008
    • 5

    Unable to upload file

    I am trying to upload a file in php,but it gives me error msg please Help me?

    My Code is like below:-
    i have one php file named upload.php and i have another html file named upload.html and inside html i am calling php file



    upload.php:-
    [code=php]
    <?php
    echo 'Name: '.$_FILES['userfile']['name'];
    echo '<br />';
    echo 'File type: '.$_FILES['userfile']['type'];
    echo '<br />';
    echo 'File size: '.$_FILES['userfile']['size'];
    echo '<br />';
    echo 'File temporary name: '.$_FILES['userfile']['tmp_name'];
    echo '<br />';
    echo 'File error: '.$_FILES['userfile']['error'];
    echo '<br />';

    if($_FILES['userfile']['size'] > 10000)
    {
    echo '<b>File Size too big.</b>';
    }
    elseif((move_up loaded_file($_F ILES['userfile']['tmp_name'], "C:\Program Files\EasyPHP 2.0b1\www\File Handling")))
    {
    echo '<b>Your file has been uploaded successfully.</b><br /><a href="files/'.$_FILES['userfile']['name'].'">Check it out here</a>';
    }
    else echo '<i>Error while uploading!</i>';

    ?>
    [/code]


    upload.html:-
    [code=html]
    <html>
    <head>
    <title>File Upload</title>
    </head>
    <body>

    <h1>Upload a file</h1>

    <form enctype="multip art/form-data" action="upload. php" method="post">
    <p>
    <input type="hidden" name="max_file_ size" value="10000">

    Choose a file: <input name="userfile" type="file" >
    </p>

    <p>
    <input type="submit" value="Send File"></p>

    </form>
    </body>
    </html>
    [/code]
    When i am running it gives me the following message:-
    Code:
    Name: testfile.txt
    File type: text/plain
    File size: 42
    File temporary name: C:/Program Files/EasyPHP 2.0b1\tmp\php1AD.tmp
    File error: 0
    
    Warning: move_uploaded_file(C:\Program Files\EasyPHP 2.0b1\www\File Handling) [function.move-uploaded-file]: failed to open stream: Permission denied in C:\Program Files\EasyPHP 2.0b1\www\File Handling\upload.php on line 21
    
    Warning: move_uploaded_file() [function.move-uploaded-file]: Unable to move 'C:/Program Files/EasyPHP 2.0b1\tmp\php1AD.tmp' to 'C:\Program Files\EasyPHP 2.0b1\www\File Handling' in C:\Program Files\EasyPHP 2.0b1\www\File Handling\upload.php on line 21
    Error while uploading!
    Last edited by Atli; Sep 19 '08, 02:51 PM. Reason: Added [code] tags.
  • Atli
    Recognized Expert Expert
    • Nov 2006
    • 5062

    #2
    Hi.

    Please use &#91;code] tags when posting your code examples.

    &#91;code] ...Code goes here.. [/code]

    Thank you.
    Moderator

    Comment

    • Atli
      Recognized Expert Expert
      • Nov 2006
      • 5062

      #3
      I'm guessing the problem is that you are trying to save your new file as a directory.

      You need to give it an actual file name, not just a directory.
      For example:
      [code=php]
      $newFile = "C:/path/to/my/file/". $_FILES['file']['name'];

      if(move_uploade d_file($_FILES['file']['tmp_name'], $newFile)) {
      echo "Success!";
      }
      else {
      echo "Failure!";
      }
      [/code]

      Comment

      • surajhs
        New Member
        • Jul 2008
        • 13

        #4
        Hey it is server side scripting language why you want to store it in local path


        Try like this
        move_uploaded_f ile($_FILES['userfile']['tmp_name'], "files/".$_FILES['userfile']['name']);

        Comment

        • Markus
          Recognized Expert Expert
          • Jun 2007
          • 6092

          #5
          Originally posted by surajhs
          Hey it is server side scripting language why you want to store it in local path


          Try like this
          move_uploaded_f ile($_FILES['userfile']['tmp_name'], "files/".$_FILES['userfile']['name']);
          He may use a direct path, if he wishes.

          Comment

          • Nelluru
            New Member
            • Mar 2007
            • 31

            #6
            hi
            Change permissions to Full control or Modify for the output folder. To my knowledge, If server is IIS one has to change the folder permissions.

            regards
            Nelluru

            Comment

            Working...