fopen errors, help please

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
bmx269
Forum Newbie
Posts: 7
Joined: Thu Oct 31, 2002 5:09 pm

fopen errors, help please

Post 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
seg
Forum Commoner
Posts: 38
Joined: Thu Oct 31, 2002 12:08 pm
Location: Northern, VA
Contact:

Re: fopen errors, help please

Post by seg »

bmx269
Forum Newbie
Posts: 7
Joined: Thu Oct 31, 2002 5:09 pm

Post 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
seg
Forum Commoner
Posts: 38
Joined: Thu Oct 31, 2002 12:08 pm
Location: Northern, VA
Contact:

Post 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.
User avatar
twigletmac
Her Royal Site Adminness
Posts: 5371
Joined: Tue Apr 23, 2002 2:21 am
Location: Essex, UK

Post 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
bmx269
Forum Newbie
Posts: 7
Joined: Thu Oct 31, 2002 5:09 pm

Post 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.
bmx269
Forum Newbie
Posts: 7
Joined: Thu Oct 31, 2002 5:09 pm

Post by bmx269 »

I changed the code to the last one posted, I did not get any errors, the image also was not uploaded
bmx269
Forum Newbie
Posts: 7
Joined: Thu Oct 31, 2002 5:09 pm

Post by bmx269 »

ok, I checked the sql database and the image has not been added to the DB.
User avatar
twigletmac
Her Royal Site Adminness
Posts: 5371
Joined: Tue Apr 23, 2002 2:21 am
Location: Essex, UK

Post by twigletmac »

Where do these variables:

Code: Select all

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

Mac
bmx269
Forum Newbie
Posts: 7
Joined: Thu Oct 31, 2002 5:09 pm

Post 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>
User avatar
twigletmac
Her Royal Site Adminness
Posts: 5371
Joined: Tue Apr 23, 2002 2:21 am
Location: Essex, UK

Post 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
Post Reply