Hi,
I've been busy writing a script to upload photo's to my webserver, and after a lot of searching I finally managed to get the permissions correct, but now I'm having another problem. There are quite a lot of posts about it, but they all come down to having the wrong path, but for as far as I can see the server is crazy :P anywho, errors (last is output of my script):
Warning: move_uploaded_file(contacts/banner.png) [function.move-uploaded-file]: failed to open stream: No such file or directory in /home/xxx/domains/xxx.nl/public_html/test/contacts/maakprof.php on line 23
Warning: move_uploaded_file() [function.move-uploaded-file]: Unable to move '/tmp/phpZ20V6B' to 'contacts/banner.png' in /home/xxx/domains/xxx.nl/public_html/test/contacts/maakprof.php on line 23
Copy unsuccessful
and my php script:
$con = mysql_connect("localhost","name","pass");
if(!$con){die('Could not connect: ' . mysql_error());}
mysql_select_db("dbname", $con);
//define a max size for the uploaded images in Kb
define ("MAX_SIZE","75");
if(isset($_FILES['foto']['name']) && $_FILES['foto']['name']<>""){
$typ = $_FILES['foto']['type'];
if($typ == "image/gif" || $typ == "image/png" || $typ == "image/jpeg" || $typ == "image/pgif" || $typ == "image/ppng" || $typ =="image/pjpeg")
{
$uploaddir = "contacts/";
$uploadimages = $uploaddir.basename($_FILES['foto']['name']);
if(move_uploaded_file($_FILES['foto']['tmp_name'], $uploadimages)){
echo "File successfully copied";
$sql="INSERT INTO contacts (Naam, Leeftijd, Foto, Beschrijving)
VALUES ('$_POST[naam]','$_POST[leeftijd]','$uploadimages',
'$_POST[beschrijving]')";
if (!mysql_query($sql,$con)){
die('Error: ' . mysql_error());
mysql_close($con);
}
}
else{echo "Copy unsuccessful";}
}
else{
echo "Incorrect file type";
}
}
else{
echo "No file selected";
}
?>
and my html form:
<form name="loginform" action="contacts/maakprof.php" enctype="multipart/form-data" method="post">
<div align="center">
<table width="400" border="0">
<tr>
<td><table width="200" border="1" align="center">
<tr>
<td>Naam
<input type="text" name="naam" maxlength="50" /></td>
<td>Leeftijd
<input type="text" name="leeftijd" maxlength="3" /></td>
</tr>
</table></td>
</tr>
<tr>
<td><div align="center">Foto
<input name="foto" type="file" size="35" />
</div></td>
</tr>
</table>
</div>
<p align="center">Beschrijving<br />
<textarea name="beschrijving" cols="75" rows="15" ></textarea>
</p>
<div align="center">
<input type="submit" value="Voeg toe" />
</div>
</form>
The reason I've put the php file to process the data in the folder where the pictures must go is that I only have to extend permission for that folder. I'm kind of new with the direct access to the server using php, so any advice is welcome.
Note: Everything works except uploading the file to the server.
Thanks in advance,
Regards,
Anti