i was wondering what the best way to store a file name in a field. i dont mind if the extension is chopped off or not.. so far i have
$fname = $_FILES["name"];
mysql_connect('myssdfebhost.com',$username,$password);
@mysql_select_db($database) or die( "Unable to select database");
$query = "INSERT INTO uploadedfiles (fi开发者_如何学Clename) VALUES ('$fname')";
mysql_query($query);
but it doesnt put it in
A couple of things to note :
- I don't think you can use
$_FILES["name"]
:- instead, you should use
$_FILES['NAME OF YOUR INPUT FIELD']["name"]
- instead, you should use
- You should escape
$fname
withmysql_real_escape_string()
, to avoid SQL injections. - The uploaded file is uploaded to a temporary directory ; if you do not move it to a non-temporary location, it will automatically be deleted.
- See the
move_uploaded_file()
function, about that, if you want to keep the file.
- See the
It could be interesting for you to use the following portion of code :
var_dump($_FILES);
This will show you what's in the $_FILES
array, so you know what you can use -- typically, you'll see the structure of that array, including the key that correspond to the name
attribute of the <input type="file" ... />
of your form.
About that $_FILES
variable, btw, you should take a look at the following section of the manual : POST method uploads.
精彩评论