Been away and brainwahed :S

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
ericburnard
Forum Contributor
Posts: 104
Joined: Wed Jun 15, 2005 5:11 pm
Location: Chesterfield, UK

Been away and brainwahed :S

Post 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 :D 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 :D
josh
DevNet Master
Posts: 4872
Joined: Wed Feb 11, 2004 3:23 pm
Location: Palm beach, Florida

Post by josh »

http://www.php.net/features.file-upload

store your images on the filesystem, use the database to keep track of them
User avatar
Chris Corbyn
Breakbeat Nuttzer
Posts: 13098
Joined: Wed Mar 24, 2004 7:57 am
Location: Melbourne, Australia

Post by Chris Corbyn »

Upload.... (dont forget enctype="multipart/form-data" in the <form /> tag)

Code: Select all

<input type="file" name="foo" />

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="" />';
Post Reply