I have this short script to upload files and data.
<?php
//This is the directory where images will be saved
$target = "images/"; $target = $target . basename( $_FILES['photo']['name']);
//This gets all the other information from the form
$name=$_POST['name']; $email=$_POST['email']; $phone=$_POST['phone']; $pic=($_FILES['photo']['name']);
$con = mysql_connect("xxxxxxxxx","xxxxxxxxx","xxxxxxxxxx");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
mysql_select_db("xxxxxxxxx", $con);
//Writes the information to the database
mysql_query("INSERT INTO `gallery` VALUES ('$name', '$email', '$phone', '$pic')") ;
//Writes the photo to the server
if(move_uploaded_file($_FILES['photo']['tmp_name'], $target)) {
//Tells you if its all ok
echo "The file ". basename( $_FILES['uploadedfile']['name']).
" has been uploaded, and your information has been added to the directory"; }
else {
//Gives and error if its not
echo "Sorry, there was a problem uploading your file."; }
//DISCONNECT FROM DATABASE
mysql_close($con);
?>
I always get this error and can’t seem to make it go away. There is a directory called “images” on the server at the root level.
Here’s the error…
Warning: move_uploaded_file(images/favicon.gif) [function.move-uploaded-file]: failed to open stream: No such file or directory in /home/fhlinux009/n/mysite.co.uk/user/htdocs/datasub/add.php on line 24
Warning: move_uploaded_file() [function.move-uploaded-file]: Unable to move ‘/tmp/phpfpCvah’ to ‘images/favicon.gif’ in /home/fhlinux009/n/mysite.co.uk/user/htdocs/datasub/add.php on line 24
Sorry, there was a problem uploading your file.
Can anyone spot where 'm going wrong please?