Page 1 of 1
Been away and brainwahed :S
Posted: Mon Dec 05, 2005 1:54 pm
by ericburnard
hello agian everyone. ive been away for a while, so you guys have had chance to recover from my tedious and ranom questions

but while i was away i seem to have forgotten some stuf. Now im re-doing my site i need to do a new photo gallery but dont understand how to upload thigs to the server, and put the data in a database.
help please!!!
Eric

Posted: Mon Dec 05, 2005 2:27 pm
by josh
http://www.php.net/features.file-upload
store your images on the filesystem, use the database to keep track of them
Posted: Mon Dec 05, 2005 2:58 pm
by Chris Corbyn
Upload.... (dont forget enctype="multipart/form-data" in the <form /> tag)
Code: Select all
if (!empty($_FILES['foo']))
{
$name = mysql_real_escape_string(time().$_FILES['name']);
move_uploaded_file($_FILES['tmp_name'], '/home/usrname/public_html/img/'.$filename);
$query = "insert into tbl_name (userid, filename, date) values ('{$_SESSION['user']}', '{$name}', now()";
if (mysql_query($query)) echo 'File uploaded successfully';
}
Retreive....
Code: Select all
$query = "select filename from tbl_name where id = $file_id";
$result = mysql_query($query);
$name = mysql_result($result, 0, 0);
echo '<img src="/img/'.$name.'" alt="" />';