Simple upload script not working

Reply

Join Date: Oct 2008
Posts: 8
Reputation: twmprys is an unknown quantity at this point 
Solved Threads: 0
twmprys twmprys is offline Offline
Newbie Poster

Simple upload script not working

 
0
  #1
Oct 13th, 2008
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.
Reply With Quote Quick reply to this message  
Join Date: Jul 2004
Posts: 234
Reputation: PoA is an unknown quantity at this point 
Solved Threads: 8
PoA PoA is offline Offline
Posting Whiz in Training

Re: Simple upload script not working

 
0
  #2
Oct 13th, 2008
Post your codes in code tag. Have you tried chmod 777 on destination folder?
Reply With Quote Quick reply to this message  
Join Date: Oct 2008
Posts: 8
Reputation: twmprys is an unknown quantity at this point 
Solved Threads: 0
twmprys twmprys is offline Offline
Newbie Poster

Re: Simple upload script not working

 
0
  #3
Oct 13th, 2008
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:
  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
Reply With Quote Quick reply to this message  
Join Date: Jul 2004
Posts: 234
Reputation: PoA is an unknown quantity at this point 
Solved Threads: 8
PoA PoA is offline Offline
Posting Whiz in Training

Re: Simple upload script not working

 
0
  #4
Oct 13th, 2008
  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.,
  1. move_uploaded_file($_FILES['news1']['tmp_name'], '/home/<your_username>/htdocs/files/news1.jpg');
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC