Reputation: 941
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 (filename) VALUES ('$fname')";
mysql_query($query);
but it doesnt put it in
Upvotes: 0
Views: 481
Reputation: 400972
A couple of things to note :
$_FILES["name"]
:
$_FILES['NAME OF YOUR INPUT FIELD']["name"]
$fname
with mysql_real_escape_string()
, to avoid SQL injections.move_uploaded_file()
function, about that, if you want to keep the file.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.
Upvotes: 3