I'm trying to get this image upload function to work, and I'm stuck at a seemingly simple problem I can't solve.
Here's the file with everything all-inclusive:
<?php
//***DB connect info omitted
if ($do_add == 'yes') {
$dest = "../images/uploaded/";
//Full path used, I truncated for privacy
if ($userfile_name != '') {
if($userfile_size > 80000) {
echo "File size is bigger than 80kb!";
exit;
}
copy($userfile, $dest.$userfile_name)
or die("No copy!");
} else {
die("No input file!");
}
$title_slash = addslashes($title);
$descr_slash = addslashes($description);
$query= "insert into $subject
(img_name,title,descr,cat_id,height,width) values
('" . $userfile_name . "','" . $title_slash . "',
'" . $descr_slash . "','" . $cat_id . "',
'" . $img_size[0] . "','" . $img_size[1] . "')";
mysql_query($query);
echo "Image uploaded successfully.<br><br><br>";
$do_update = 'no';
}
else {
echo "<form action=$PHP_SELF method=post enctype='multipart/form-data'> \n
<table border=0>\n
<tr>\n
<td valign=top>Category: </td>\n
<td valign=top>\n";
include ("pages/dropdown_images_cat.inc");
echo "</td>\n
</tr>\n
<tr>\n
<td valign=top>Image: </td>\n
<td valign=top><INPUT TYPE=hidden name=MAX_FILE_SIZE value=80000>\n
<INPUT NAME='userfile' TYPE=file></td>\n
</tr>\n
<tr>\n
<td valign=top>Title: </td>\n
<td valign=top><input type=text name=title size=40></td>\n
</tr>\n
<tr>\n
<td valign=top>Description: </td>\n
<td valign=top><textarea name=description rows=10 cols=40></textarea></td>\n
</tr>\n
</table>\n
<input type=hidden name='db_type' value=$db_type>\n
<input type=hidden name='do_add' value='yes'>\n
<input type=submit value='Submit Form'>\n
<input type=reset value='Reset Form'>\n
</form>\n";
}
?>
Even though I've checked it over several times and it seems correct, I keep getting the following error message:
Warning: Unable to create '../images/uploaded/pic.jpg': No such file or directory in ../add_images.php on line 36
Again, the full path is shown, but I need my privacy.
I commented out the copy() section and echoed the mysql query, and everything looked the way it should (image name and dimensions came out right, etc.). I double-checked, and yes, the /uploaded/ file is CHMODed 777.
I decided to echo $userfile, and got this:
/var/tmp//phpQ0NlWC
Could the double slashes be the reason I'm getting nowhere? It seems likely to me that it's causing the problem, but I have no idea where the extra slash is coming from.
Help?
http://www.bisonman.com