[nycphp-talk] next challenge
Steve Manes
smanes at magpie.com
Sun May 11 22:09:32 EDT 2003
Joshua S. Freeman wrote:
> The problem is, on submit, I need different form values to be
submitted to
> different tables in the database. How do I build an insert statement like
> that?
You can't. You need to build lots of insert statements, ideally wrapped
in a transaction so you can roll back in case one of them fails.
> How is *this* accomplished? *this* being... asking for someone to somehow
> insert the local image path and then, on submit, moving the image to the
> right place on the server and creating the 'url' that goes into the database
> and putting it in the database?
You definitely don't want to write to user-provided directories. There
are a number of solutions, one of them something I've done for years and
what we do at CCI as well. Assign a unique id to the image, convert
that id to an MD5 hash, breaking it out into two or three nodes like
957/ae1. Then you would write the image to
IMAGE_DIR/957/ae1/IMAGE_ID.gif (or whatever extension).
To play it back to the user's browser:
<?php
$hash_string = md5($image_id);
$node1 = substr($hash_string, 0, 3);
$node2 = substr($hash_string, 3, 3)
$image_ref = IMAGE_DIR . "/$node1/$node2/${image_id}.gif";
?>
<IMG SRC="<?= $image_ref ?>" BORDER="0">;
An added advantage to this approach is that it balances out the image
directory tree naturally so you don't have ten zillion files in the
"Jan" directory and only a few in the "Feb" directory.
More information about the talk
mailing list