I created a page that can add new records to my database, everything is working fine but when I\'m trying to upload a pdf file, it doesn\'t store to the correct folder. It shoul
That's because you set only to save file name
$file = $_REQUEST['file'];
Instead it should be
$file = "../uploads/".$_REQUEST['file'];
There are quite a few logical errors in your code.
You are inserting a record into the MySQL database before you do your check on the file extension and file size.
You just insert the file name into MySQL ($file = $_REQUEST['file'];
), hence only the file name appears there. The correct code would be:
$file = "../uploads/".$_FILES['file']['name'];
A bit more down you need to adjust the file move part:
move_uploaded_file($file_tmp, $file);
In the error checking after the sql insert you use mysql_error()
, not mysqli_error($con)
You do not check if the move_uploaded_file($file_tmp,"../uploads/".$file_name);
call was successful and the file was moved to its final location.
Also pls consider using prepared statements to prevent sql injection attacks.