Page 1 of 1

fopen errors, help please

Posted: Fri Nov 08, 2002 12:44 pm
by bmx269
I updated my php which broke alot of my code, I am still stuck on the fopen command. here is my code

Code: Select all

<$binary_junk = addslashes (fread(fopen($img1, "r"), filesize($img1)));
mysql_query("INSERT INTO images (product_itemcode, binary_junk, filename, filesize, filetype) 
VALUES ("$product_itemcode", "$binary_junk", "$img1_name", "$img1_size", "$img1_type")");>
I get an error and need help on this, thanks

Re: fopen errors, help please

Posted: Fri Nov 08, 2002 1:03 pm
by seg

Posted: Fri Nov 08, 2002 1:12 pm
by bmx269
I tried "a" still doesnt work, here is the error

Warning: fopen("", "a") - Undefined error: 0 in /Library/WebServer/Documents/datasheet/add_product.php on line 157

Warning: stat failed for (errno=2 - No such file or directory) in /Library/WebServer/Documents/datasheet/add_product.php on line 157

Warning: fread(): supplied argument is not a valid File-Handle resource in /Library/WebServer/Documents/datasheet/add_product.php on line 157

Posted: Fri Nov 08, 2002 1:24 pm
by seg
To better locate the actual problem, break down the code...

Code: Select all

<?php
<$binary_junk = addslashes (fread(fopen($img1, "r"), filesize($img1))); 
?>
why is there a "<" before the variable?

Code: Select all

&lt;?php
$binary_junk = addslashes(fread(fopen($img1, "r"), filesize($img1)));
?&gt;
to help, make this look stupid and bloated....

Code: Select all

&lt;?php
$fp = fopen($img1, "a");
$binary_junk = fread($fp, filesize($img1));
$binary_junk = addslashes($binary_junk);
?&gt;
that will give you a more specific point to look at when you get an error. It's easier to touble shoot 3 functions on three lines when the error gives you one line as the trouble spot.

Posted: Mon Nov 11, 2002 2:41 am
by twigletmac
Another thing to do to aid debugging is to make sure that your SQL statements are in their own variable so that you can echo them out in case anything goes wrong with them and use error handling on the mysql_query() call:

Code: Select all

$sql = "INSERT INTO images (product_itemcode, binary_junk, filename, filesize, filetype) ";
$sql .= "VALUES ('$product_itemcode', '$binary_junk', '$img1_name', '$img1_size', '$img1_type')";

@mysql_query($sql) or die(mysql_error().'&lt;p&gt;'.$sql.'&lt;/p&gt;');
Out of interest, what exactly is the error that you are getting? Also what OS are you using - and if applicable (ie. you're not on Windows 9x) do you have the required permissions to access the file you want to?

Mac

Posted: Tue Nov 12, 2002 10:11 am
by bmx269
I am running the apache server on Macos X 10.2.1. My fopen code worked before I updated to the newer release of PHP. This is why im stuck. I hope this can help you help me. Sounds like a beattles song. lol.

Posted: Tue Nov 12, 2002 10:14 am
by bmx269
I changed the code to the last one posted, I did not get any errors, the image also was not uploaded

Posted: Tue Nov 12, 2002 10:58 am
by bmx269
ok, I checked the sql database and the image has not been added to the DB.

Posted: Tue Nov 12, 2002 1:26 pm
by twigletmac
Where do these variables:

Code: Select all

$product_itemcode, $binary_junk, $img1_name, $img1_size, $img1_type
come from?

Mac

Posted: Tue Nov 12, 2002 1:53 pm
by bmx269
here is the part in the form where the image comes from:

<tr align=\"LEFT\" valign=\"top\">
<td width=\"20\" class=\"underline\" bgcolor=\"#CCCCCC\"><font face=\"Verdana, Arial, Helvetica, sans-serif\" size=\"-7\">Picture</font></td>
<td width=\"30\" class=\"underline\"><font size=\"-7\" face=\"Verdana, Arial, Helvetica, sans-serif\">
<input type=\"file\" size=\"30\" name=\"img1\">
</font></td>

Posted: Wed Nov 13, 2002 2:41 am
by twigletmac
Since the data is coming from a form you should have a read of this:
viewtopic.php?t=511

Also for file uploading:
http://www.php.net/manual/en/features.file-upload.php

Mac