Underdog Underdog - 1 year ago 61
MySQL Question

file not found after upload in php and mysql

I would like to upload some files to my server. So far, they have been successfully stored in a MySQL database, but the problem is that the uploaded file is not found in a folder that is located on the server.

Here's my code:

$dir = $filename;
$target_dir = "file/$dir/";
if( is_dir($target_dir) === false )

if(isset($_POST["submit"])) {
$formatfile = array('pdf');
$filetest= $_FILES['filetest']['name'];
$x = explode('.', $filetest);
$existence= strtolower(end($x));
$pdfsize = $_FILES['filetest']['size'];
$file_tmp = $_FILES['filetest']['tmp_name'];

if(in_array($existence, $formatfile) === true){

if($pdfsize < 1044070){
move_uploaded_file($file_tmp, "$target_dir.$filetest");
$sql = "INSERT INTO test (filename) VALUES ('$filetest')";

Is there anything I missed?

Answer Source

Please change $formatfile = array('pdf') to $formatfile = array('.pdf'=>'application/pdf');

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download