TheJuan
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/pr oduct/uplo ad.php on line 27
Could not copy.....
i change the "files/".$_FILES['imagefil e']['name' ]) to "/usr/local/www/data/adf/p roduct/fil es/".$_FIL ES['imagef ile']['nam e']) fullpath and i got this msg:
Warning: Unable to create '/files/Image5.jpg': No such file or directory in /usr/local/www/data/adf/pr oduct/uplo ad.php on line 27
Could not copy.....
this is my script filenamed: upload.php
<form method="POST" action="" enctype="multipart/form-da ta">
<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']['typ e'] == "image/gif") || ($_FILES['imagefile']['typ e'] == "image/pjpeg") ){
copy ($_FILES['imagefile']['tmp _name'], "files/".$_FILES['imagefil e']['name' ]) or die ("Could not copy.....");
$strDescription = addslashes(nl2br($txtDescr iption));
$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']['si ze']."";
echo "Type: ".$_FILES['imagefile']['ty pe']."";
echo "Copy Done....";
}
else {
echo "";
echo "Could Not Copy, Wrong Filetype (".$_FILES['imagefile']['n ame'].")";
}
}
?>
Warning: Unable to open 'none' for reading: No such file or directory in /usr/local/www/data/adf/pr
Could not copy.....
i change the "files/".$_FILES['imagefil
Warning: Unable to create '/files/Image5.jpg': No such file or directory in /usr/local/www/data/adf/pr
Could not copy.....
this is my script filenamed: upload.php
<form method="POST" action="" enctype="multipart/form-da
<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 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",
mysql_select_db("adf");
if(isset( $Submit ))
{
//If the Submitbutton was pressed do:
if ( ($_FILES['imagefile']['typ
copy ($_FILES['imagefile']['tmp
$strDescription = addslashes(nl2br($txtDescr
$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']['si
echo "Type: ".$_FILES['imagefile']['ty
echo "Copy Done....";
}
else {
echo "";
echo "Could Not Copy, Wrong Filetype (".$_FILES['imagefile']['n
}
}
?>
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
You can also get any other vars from the form and just save 'em into the DB, that ain't no big deal...
Warning: imagejpeg(): Invalid filename ''
// PREPARE FOR INSERT
imagejpeg($newImage,$filen ame);
it was inserting into the database before we did all this, so i do not think its anything suggested on the other PAQ
// PREPARE FOR INSERT
imagejpeg($newImage,$filen
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)
$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.
duh wrong thread.