Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: PHP
how to upload file or images in php form
Posted 8-Feb-13 4:02am
Comments
Marcus Kramer at 8-Feb-13 10:13am
   
Next time you have a question, please read the following that appears at the bottom of the ask a question form:

A few simple rules when posting your question.
1) Have you searched or Googled for a solution?
2) Be specific! Don't ask "I need to write a booking application". Specify exactly what it is you need help with.
3) Keep the subject brief but descriptive. eg "How do I change the dialog colour?"
4) Keep the question as concise as possible. If you have to include code, include the smallest snippet of code you can - do not dump your entire codebase.
5) Tag your question appropriately.
6) Your question may be edited or retagged by others. Anything inappropriate will be removed.
7) If you have a school or university assignment, assume that your teacher or lecturer is also reading these forums.
8) Be courteous and DON'T SHOUT. Everyone here helps because they enjoy helping others, not because it's their job.
9) Do not remove or empty a message if others have replied. Keep the thread intact and available for others to search and read.
10) Do not be abusive, offensive, inappropriate,harass anyone on the boards or post ads or spam. Doing so will get you kicked off and banned. Play nice.
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

  Permalink  
Comments
Marcus Kramer at 8-Feb-13 10:13am
   
+5.
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

Basically you have to create a <form> and there must be multipart/form-data to upload a file.
Something like:
 
<html>
<body>
 
<form action="upload_file.php" method="post">
enctype="multipart/form-data">
<label for="file">Filename:</label>
<input type="file" name="file" id="file"><br>
<input type="submit" name="submit" value="Submit">
</input></br></input></form>
 
</body>
</html> 
 
And in the PHP file something like that:
 
if ($_FILES["file"]["error"] > 0)
  {
  echo "Error: " . $_FILES["file"]["error"] . "<br>";
  }
else
  {
  echo "Upload: " . $_FILES["file"]["name"] . "<br>";
  echo "Type: " . $_FILES["file"]["type"] . "<br>";
  echo "Size: " . ($_FILES["file"]["size"] / 1024) . " kB<br>";
  echo "Stored in: " . $_FILES["file"]["tmp_name"];
  }
?>
 
But is better you read: http://www.w3schools.com/php/php_file_upload.asp
  Permalink  
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 mhegazy94 460
1 Sergey Alexandrovich Kryukov 405
2 Kornfeld Eliyahu Peter 285
3 Gihan Liyanage 167
4 Sibeesh KV 150
0 Sergey Alexandrovich Kryukov 6,805
1 OriginalGriff 6,696
2 CPallini 5,350
3 George Jonsson 3,609
4 Gihan Liyanage 2,792


Advertise | Privacy | Mobile
Web04 | 2.8.140922.1 | Last Updated 19 Feb 2013
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100