Page 1 of 1
Retrieving text from a file field?
Posted: Sat May 10, 2003 11:30 pm
by skylavelle
Hey, does anyone know how to retrieve text from a file field?
Basically, what I am trying to do in (1) upload an image and (2) take the file name and path that it is uploaded to and insert it into my MySQL database.
Cheers
Sky

Posted: Sun May 11, 2003 2:59 am
by pootergeist
personally I'd advise reversing that logic and naming the file based on an auto_inc db field return - basically, if two people uploaded an image called blat.jpg what would happen with your version? would the old be overwritten?
$q = mysql_query("INSERT INTO `images` VALUES ('' , $title, $dimensions, $size)");
$n = mysql_insert_id();
move_uploaded_file($_FILES['formfield']['tmp_name'], '../images/' .$n. '.jpg');
if `images` was
id - auto_increment primary
title - varchar(100)
dims - varchar(100)
size - mediumint(6)
the auto increment value of id would be returned to $n and then the image named when it gets moved from /tmp/ - no images would ever be overwritten.
Posted: Sun May 11, 2003 1:17 pm
by m3mn0n
yea, adding on to what he wrote:
the
$_FILES['variable'] superglobal is made for this.
You can research it more here:
http://www.php.net/manual/en/security.r ... lobals.php
also the sticky on this forum:
http://www.devnetwork.net/forums/viewtopic.php?t=511