473,401 Members | 2,127 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,401 software developers and data experts.

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:-
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
5 6778
Atli
5,058 Expert 4TB
Hi.

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

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

Thank you.
Moderator
Sep 19 '08 #2
Atli
5,058 Expert 4TB
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
surajhs
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
6,050 Expert 4TB
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
Nelluru
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

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

Similar topics

2
by: Ruddy | last post by:
hi, i´m trying to upload a file. I tried many ways but it always return the same error... Unable to open c:\file.jpg for reading. the file exists, but any file gives me the same error.. ...
1
by: PeterB | last post by:
Hi! I'm using Pure ASP File Upload (http://www.asp101.com/articles/jacob/scriptupload.asp) to upload a file from a client to a server. I am testing both on a local IIS and a remote server. The...
1
by: paras | last post by:
I am using File Upload Control to upload file on server. If size of the file exceeds maxRequestLength property in httpRuntime section of my configuration file, then DNS error is thrown. how can i...
3
by: David | last post by:
I am using PHP Version 4.4.3 under Linux/Apachie to upload files. The PHP.ini upload_max_filesize is 2M, which I need to override this in the HTML (see below). I changed the MAX_FILE_SIZE to...
0
by: Buddy Home | last post by:
Hello, I'm trying to upload a file programatically and occasionally I get the following error message. Unable to write data to the transport connection: An established connection was aborted...
3
by: Buddy Home | last post by:
Hello, I'm trying to upload a file programatically and occasionally I get the following error message. Unable to write data to the transport connection: An established connection was aborted...
6
Markus
by: Markus | last post by:
I'm adding to my script a section that allows a thumbnail to be created and saved. I get this error: Warning: imagejpeg() : Unable to open '../uploads/thumb/' for writing: Is a directory in...
0
by: ll | last post by:
I'm working with 'pure ASP upload' script which is designed to redirect to an alert/error message, should a file larger than the set limit be attempted to be uploaded. The problem is that, while...
5
by: maheswaran | last post by:
Hi, i have issue in FTP , i have tried with .net and also c# Note the following scenario: 1. Upload the file to FTP >than 60 MB. 2. At the time of Uploading, unplug the LAN cable (or)...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.