Underdog Underdog - 4 months ago 10
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 )
{
mkdir($target_dir);
}

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

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