...

php posting binary to mysql: script question...

russcrosbie2002
10-11-2002, 11:18 PM
I have a php script that writes binary (image) files posted from a html form to a mysql database.

if (!$prod_file) $prod_file = "..\images\warning.gif";
$prod_file = addslashes(fread(fopen($prod_file, "r"), filesize($prod_file)));

and writes a default file (warning.gif) when an image is not posted from the form page.

This works locally on my 'localhost' setup running the latest versions of PHP and MYSQL on IIS5.1. But when I upload the database and scripts to my ISP, whose phpinfo() parameters are set identically to mine (although they are running IIS4 with slightly older versions of PHP and MYSQL , i get an error when it tries to find and write the default file. Otherwise files that are posted as $prod_file are recognised and written to the db.

errors are as follows:

Warning: fopen("none","r") - No such file or directory in xyz

Warning: stat failed for none (errno=2 - No such file or directory) in xyz

Warning: Supplied argument is not a valid File-Handle resource in xyz.

The rest of the fields (varchar and so on) are written properly despite the error.

Could anyone suggest a solution cos I am at my wit's end and have 3 question marks hanging over my gradually balding cranium. All help gratefully recieved may lower my blood pressure!
:confused:

Regds

Russ.

Ökii
10-14-2002, 05:26 PM
The main differences you'd spot between localhost and sitehost would be the path system - until I upgraded my localhost, defining file paths was an illogical minefield.

Primarily (online) all relative paths will be in reference to the heirarchically top containing document [yeppy - that makes sense]

Your scriptlet is simply telling you that the defined image is not where you reference it to be - so change the path...

if (!$prod_file) $prod_file = "..\images\warning.gif";

if (!$prod_file) $prod_file = "\root\usr\whatever\images\warning.gif";

or just try changing the \ bits to / - at least the one-dir-up might be recognised then.

russcrosbie2002
10-15-2002, 07:23 PM
if ($prod_file=="none") $prod_file = ("../images/warning.gif");

seems to have fixed it. makes sense now, suppose $prod_file was submitted all along, yet originally, !$prod_file was checking for the existance of the string, whereas above, it is checking for the value within the string.

Doh!

Thanks anyhows, i did try all permutations on the paths, before I tried something random.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum