By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
434,577 Members | 864 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 434,577 IT Pros & Developers. It's quick & easy.

Unable to upload file

P: 5
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:-
Expand|Select|Wrap|Line Numbers
  1. <?php
  2. echo 'Name: '.$_FILES['userfile']['name'];
  3. echo '<br />';
  4. echo 'File type: '.$_FILES['userfile']['type'];
  5. echo '<br />';
  6. echo 'File size: '.$_FILES['userfile']['size'];
  7. echo '<br />';
  8. echo 'File temporary name: '.$_FILES['userfile']['tmp_name'];
  9. echo '<br />';
  10. echo 'File error: '.$_FILES['userfile']['error'];
  11. echo '<br />';
  12.  
  13. if($_FILES['userfile']['size'] > 10000)
  14. {
  15.     echo '<b>File Size too big.</b>';
  16. }
  17. elseif((move_uploaded_file($_FILES['userfile']['tmp_name'], "C:\Program Files\EasyPHP 2.0b1\www\File Handling")))
  18. {
  19.     echo '<b>Your file has been uploaded successfully.</b><br /><a href="files/'.$_FILES['userfile']['name'].'">Check it out here</a>';
  20. }
  21. else echo '<i>Error while uploading!</i>';
  22.  
  23. ?>
  24.  

upload.html:-
Expand|Select|Wrap|Line Numbers
  1. <html>
  2. <head>
  3. <title>File Upload</title>
  4. </head>
  5. <body>
  6.  
  7. <h1>Upload a file</h1>
  8.  
  9. <form enctype="multipart/form-data" action="upload.php" method="post">
  10. <p>
  11. <input type="hidden" name="max_file_size" value="10000">
  12.  
  13. Choose a file: <input name="userfile" type="file" >
  14. </p>
  15.  
  16. <p>
  17. <input type="submit" value="Send File"></p>
  18.  
  19. </form>
  20. </body>
  21. </html>
  22.  
When i am running it gives me the following message:-
Expand|Select|Wrap|Line Numbers
  1. Name: testfile.txt
  2. File type: text/plain
  3. File size: 42
  4. File temporary name: C:/Program Files/EasyPHP 2.0b1\tmp\php1AD.tmp
  5. File error: 0
  6.  
  7. 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
  8.  
  9. 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
  10. Error while uploading!
Sep 19 '08 #1
Share this Question
Share on Google+
5 Replies


Atli
Expert 5K+
P: 5,058
Hi.

Please use [code] tags when posting your code examples.

[code] ...Code goes here.. [/code]

Thank you.
Moderator
Sep 19 '08 #2

Atli
Expert 5K+
P: 5,058
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:
Expand|Select|Wrap|Line Numbers
  1. $newFile = "C:/path/to/my/file/". $_FILES['file']['name'];
  2.  
  3. if(move_uploaded_file($_FILES['file']['tmp_name'], $newFile)) {
  4.   echo "Success!";
  5. }
  6. else {
  7.  echo "Failure!";
  8. }
  9.  
Sep 19 '08 #3

P: 13
Hey it is server side scripting language why you want to store it in local path


Try like this
move_uploaded_file($_FILES['userfile']['tmp_name'], "files/".$_FILES['userfile']['name']);
Sep 23 '08 #4

Markus
Expert 5K+
P: 6,050
Hey it is server side scripting language why you want to store it in local path


Try like this
move_uploaded_file($_FILES['userfile']['tmp_name'], "files/".$_FILES['userfile']['name']);
He may use a direct path, if he wishes.
Sep 23 '08 #5

P: 31
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
Sep 24 '08 #6

Post your reply

Sign in to post your reply or Sign up for a free account.