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, 'files/pic.jpg');

Recommended Answers

All 3 Replies

Post your codes in code tag. Have you tried chmod 777 on destination folder?

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 ?>'><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 ?></textarea></td>

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

Which is passed on to a new page:

<?php
$section1=$_POST['section1'];
$section2=$_POST['section2'];
$section3=$_POST['section3'];
$section4=$_POST['section4'];
$target_path = "files/";
$target_path = $target_path . basename( $_FILES['news1']['name']); 
move_uploaded_file($_FILES['news1']['tmp_name'], 'files/news1.jpg');
$con = mysql_connect("localhost","user","pass"); 
if (!$con) 
{ 
die('Can't connect: ' . mysql_error()); 
} 
mysql_select_db("database", $con);
$query = "UPDATE news SET section1='$section1', section2='$section2', section3='$section3', section4='$section4' WHERE id='$id'";
$result = mysql_query($query);
header ( 'Location: http://www.website.com/newsc.php' );
// close connection
mysql_close();
?>
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.,

move_uploaded_file($_FILES['news1']['tmp_name'], '/home/<your_username>/htdocs/files/news1.jpg');
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.