Database path store.

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
viajero
Forum Newbie
Posts: 2
Joined: Fri Mar 31, 2006 12:14 am

Database path store.

Post by viajero »

Alright, how in the world can I do this:

uploadforms.php - A form where you simply input a title, choose a file to upload, add a comment for the file, and select a catagory for the file. All of this info is then passed onto upload.php

upload.php - this takes the info from the forms puts it in a database, I know how to get all the text into the database, but how can i store the file location of the file in the DB (the location of the file on the server)? I cannot seem to get this, and I have been at it for weeks....
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

Have a set directory where you store uploaded files. When someone uploads a file, move the file to this directory using move_uploaded_file(). If you want to keep the original name (not the best idea due to name collisions) make sure to use basename() on the filename sent as some browsers will submit the full path it had, otherwise use an md5 of a fairly unique value such as that returned by microtime() or some other form of "random" data. Store (in the database) only the filename used. No need to store more information.
viajero
Forum Newbie
Posts: 2
Joined: Fri Mar 31, 2006 12:14 am

Post by viajero »

so would this work:

Code: Select all

$filename = $file['tmp_name']
$path = move_uploaded_file($file['tmp_name'], 'images/' . $filename);

$sql = "insert into user_art
                  (title, caption, path) values
                ('$name', '$caption', '$path')";
??
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

$path will be a boolean (pass/fail for moving the file), it won't contain the path. Just store $filename, like I said already.

Other than that, it appears okay assuming several things..
Post Reply