Deepak Narwal Deepak Narwal - 8 months ago 42
PHP Question

Three problems in uploading a file into database and then how to download it back


die('Could Not Connect:'.mysql_error());


$upload_to = "./uploadedfiles/";
$upload_to . "/" . $_FILES["file"]["name"]

$sql="insert into employee values ('$_POST[username]','$_FILES[filename][name]')";

if (!mysql_query($sql,$con))
die('Error: ' . mysql_error());

echo "Employee Uploaded File"."$_FILES[file][name]"; //showing uploaded file name


But there are three problems:

  1. $sql="insert into employee values('$_POST[username]','$_FILES[filename][name]')";

this command file name is not saving in database.

And if I try
into employee values (
then a syntax error is displayed.

How do I send file name also in database? Please write or edit above code.

How do I add username id with this file so that it can be downloaded in the future?

  1. If I try the same file name from another location to store in the database (uploaded folder), then the file is still the same (only one copy after 2 times of uploading the same file name but from different locations).

  2. How to download file if user wants to download it? How server will know that this file name belongs to this user? Please tell me the code for this purpose.


Basically you store images in a folder but in the database, you store only the file names of uploaded pics. Here is how to upload the files.