Link to home
Start Free TrialLog in
Avatar of TheJuan
TheJuanFlag for Philippines

asked on

inserting data into mySQL with upload image

hi i want to upload an image to certain directory (files/) and save the other information to the database like the imagename, and description but i get this error :

Warning: Unable to open 'none' for reading: No such file or directory in /usr/local/www/data/adf/product/upload.php on line 27
Could not copy.....

i change the  "files/".$_FILES['imagefile']['name']) to  "/usr/local/www/data/adf/product/files/".$_FILES['imagefile']['name']) fullpath and i got this msg:
Warning: Unable to create '/files/Image5.jpg': No such file or directory in /usr/local/www/data/adf/product/upload.php on line 27
Could not copy.....

this is my script filenamed: upload.php
<form method="POST" action="" enctype="multipart/form-data">
<INPUT TYPE="hidden" NAME="MAX_FILE_SIZE" VALUE="10000">
<table>
<tr>
<td width="13%">Picture</td>
<td width="87%"><input type="file" name="imagefile" size="28"></td>
</tr>
<tr>
<td width="13%">Price:</td>
<td width="87%"><input type="text" name="price" size="28"></td>
</tr>
<tr>
<td width="13%">Description:</td>
<td width="87%"><textarea rows="5" name="txtDescription" cols="23"></textarea></td>
</tr>
</table>
<p align="center"><input type="submit" value="Submit" name="Submit"><input type="reset" value="Reset" name="B2"></p>
</form>
<?
$cnxdb = mysql_connect("localhost", "root", "") or die("Could not connect: " . mysql_error());
mysql_select_db("adf");

if(isset( $Submit ))
{
//If the Submitbutton was pressed do:
if ( ($_FILES['imagefile']['type'] == "image/gif") || ($_FILES['imagefile']['type'] == "image/pjpeg") ){
copy ($_FILES['imagefile']['tmp_name'], "files/".$_FILES['imagefile']['name']) or die ("Could not copy.....");

$strDescription = addslashes(nl2br($txtDescription));
$imagefile = $_FILES['imagefile']['name'];

$query = "INSERT INTO tbl_products (product_id, name, description, price) VALUES ('', '$imagefile', '$strDescription', '$price')";
mysql_query($query, $cnxdb);

echo "";
echo "Name: ".$name."";
echo "Size: ".$_FILES['imagefile']['size']."";
echo "Type: ".$_FILES['imagefile']['type']."";
echo "Copy Done....";
}
else {
echo "";
echo "Could Not Copy, Wrong Filetype (".$_FILES['imagefile']['name'].")";
}
}
?>
ASKER CERTIFIED SOLUTION
Avatar of stefanaichholzer
stefanaichholzer
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
You can also get any other vars from the form and just save 'em into the DB, that ain't no big deal...
Avatar of qwertq
qwertq

Warning: imagejpeg(): Invalid filename ''

          // PREPARE FOR INSERT
          imagejpeg($newImage,$filename);


it was inserting into the database before we did all this, so i do not think its anything suggested on the other PAQ
also i am just noticing this:

            $percent   = 0.5; //change to your resize rules
            $newwidth  = $width * $percent;
            $newheight = $height * $percent;

shouldn't it be $newwidth = '300';
and $newheight = (some kind of math to calculate new height)
um.

duh wrong thread.