Page 1 of 1

The curse of the unnamed images

Posted: Wed Apr 02, 2003 1:49 pm
by HITMAN1net
Am loading images into a MySQL db as binary data and am confused as to why the file size,name and type don't insert into the database the way I want them to.

Source available here: http://www.hitman1.net/show_binary.php

As you can see by this image: Image from http://www.df-network.com/?page=binarydata&id=3 the data is loading and showing properly.

But of course if you right click the picture, and try and save it, it is unaware that it's a small jpeg of name d4.jpg and the fields in the database are blank.

---
Ben

Posted: Wed Apr 02, 2003 2:32 pm
by pootergeist
looks like you're accessing the form passed variables archaically - you should be reading them from the $_POST array rather than as globals.

while you're here - would you mind telling me why (oh why) are you storing them in the database?

Posted: Wed Apr 02, 2003 2:54 pm
by HITMAN1net
Because the images are going to be processed in various ways. It's something i'm playing with after a question I got asked at interview at Oxford university about manipulating images.

It's not for the website or content http://www.hitman1.net runs very nicely in a well organised filesystem.

Didn't really understand what you were saying the problem was.

Thank you in advance for any time spent,

---
Ben

Posted: Wed Apr 02, 2003 3:26 pm
by pootergeist
even with processing - storing flatfiled wins hands down in most aspects.

the only reson you'd ever want to add the overhead of repeated database calls to images is if you were running distributed source (data pulled from other servers connecting to your db) or if you were CVS or searching the iptc /exif headers - and those only 1 case in 10 would properly require db.

As to the meaning of my last post -

eg.
if($binaryform_add[shortnamefp] == "1") {
$binaryform_add[fshortname] = "frontpage";
} else {
$binaryform_add[fshortname] = "$binaryform_add[shortname]";
}
accesses the form vars as globals rather than through the defined $_POSt array - you'd need register_globals set to ON (risky) to use your way

personally, I'd do the above as

$binaryform_add['fshortname'] = ($_POST['binaryform_add[shortnamefp]'] == "1") ? "fontpage" : $binaryform_add['shortname'];

assuming $binaryform_add['shortname'] has been preset.
though I'm pretty sure you'll get notices if your error reporting is strict due to the unquoted indices in the binaryform_add array of the _POST array

or
$binaryform_add['fshortname'] = ($_POST['binaryform_add']['shortnamefp'] == "1") ? "fontpage" : $binaryform_add['shortname'];

might be better - all flytyped -

if image manipulation interests you, have a look at http://www.phpclasses.org/browse.html/package/1007.html for GD libs 2+ (don't try the online demo though as my server's having snags - pesky host :( ). though I imagine that if you were into GD you'd be processing the binaries as GD2 filetype before inserting (storing) anywhere.

Posted: Wed Apr 02, 2003 3:39 pm
by pootergeist
just took a further scan at your script - looks like you have reg_globs ON if you can access the file through $binaryform_data_name

you'll probably HAVE to rewrite that script within months when your host next upgrades their version of PHP as files would need to use -

$_FILES['binaryform_data']['name'];

Posted: Wed Apr 02, 2003 4:20 pm
by HITMAN1net
Thanks for your time