Page 1 of 1

Database path store.

Posted: Fri Mar 31, 2006 12:15 am
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....

Posted: Fri Mar 31, 2006 12:27 am
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.

Posted: Fri Mar 31, 2006 12:33 am
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')";
??

Posted: Fri Mar 31, 2006 12:37 am
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..