943,608 Members | Top Members by Rank

Ad:
  • PHP Discussion Thread
  • Unsolved
  • Views: 885
  • PHP RSS
Oct 13th, 2008
0

Simple upload script not working

Expand Post »
Sorry to ask such a stupid question, but can't understand why this simple instruction to upload a file (passed from an html form) isn't working:

move_uploaded_file($_FILES['pic']['tmp_name'], 'files/pic.jpg');
Last edited by twmprys; Oct 13th, 2008 at 11:22 am.
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
twmprys is offline Offline
8 posts
since Oct 2008
Oct 13th, 2008
0

Re: Simple upload script not working

Post your codes in code tag. Have you tried chmod 777 on destination folder?
PoA
Reputation Points: 19
Solved Threads: 9
Posting Whiz in Training
PoA is offline Offline
234 posts
since Jul 2004
Oct 13th, 2008
0

Re: Simple upload script not working

Hello, thanks so much for responding. The permissions are all OK.

Here is the hmtl form(slightly truncated - with the old data from the table called up with php echos):

<form action="news2.php" enctype="multipart/form-data" method="post">
<input type=hidden name="id" VALUE='<?php echo $row['id'] ?>'><input type="hidden" name="MAX_FILE_SIZE" value="350000"><tr>
<?php echo "<img src='files/news1.jpg'>"; ?><br /><input type="hidden" name="MAX_FILE_SIZE" value="10000" />Choose picture: <input name="news1" type="file" /><?php echo $row['section1'] ?></textarea></td>

</table><p><input name="upload" type="submit" value="Upload changes">

Which is passed on to a new page:
php Syntax (Toggle Plain Text)
  1. <?php
  2. $section1=$_POST['section1'];
  3. $section2=$_POST['section2'];
  4. $section3=$_POST['section3'];
  5. $section4=$_POST['section4'];
  6. $target_path = "files/";
  7. $target_path = $target_path . basename( $_FILES['news1']['name']);
  8. move_uploaded_file($_FILES['news1']['tmp_name'], 'files/news1.jpg');
  9. $con = mysql_connect("localhost","user","pass");
  10. if (!$con)
  11. {
  12. die('Can't connect: ' . mysql_error());
  13. }
  14. mysql_select_db("database", $con);
  15. $query = "UPDATE news SET section1='$section1', section2='$section2', section3='$section3', section4='$section4' WHERE id='$id'";
  16. $result = mysql_query($query);
  17. header ( 'Location: http://www.website.com/newsc.php' );
  18. // close connection
  19. mysql_close();
  20. ?>
Last edited by cscgal; Oct 13th, 2008 at 4:08 pm. Reason: Added code tags
Reputation Points: 10
Solved Threads: 0
Newbie Poster
twmprys is offline Offline
8 posts
since Oct 2008
Oct 13th, 2008
0

Re: Simple upload script not working

php Syntax (Toggle Plain Text)
  1. move_uploaded_file($_FILES['news1']['tmp_name'], 'files/news1.jpg');
Replace files/news1.jpg with the path + image name. You need to use the full path. E.g.,
php Syntax (Toggle Plain Text)
  1. move_uploaded_file($_FILES['news1']['tmp_name'], '/home/<your_username>/htdocs/files/news1.jpg');
PoA
Reputation Points: 19
Solved Threads: 9
Posting Whiz in Training
PoA is offline Offline
234 posts
since Jul 2004

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in PHP Forum Timeline: PHP question about "while" loop
Next Thread in PHP Forum Timeline: Checkboxes





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC