У меня есть контактная форма с PHP и JQuery.
Все отлично работает, кроме файла загрузки. его не загружен в папку.
если я поместил код PHP на ту же страницу, что и HTML-страница, файл загрузки работает нормально?
HTML:
<form id="vacancy" method="post" enctype="multipart/form-data">
<label>Full name</label><input type="text" id="fullname">
<label>Please upload your cv</label><input name="uploadcv" type="file" id="uploadcv">
<input type="submit" value="Submit Application" id="submit">
</form>
JQuery:
$("#vacancy").submit(function() {
$.post ( "include/vacancy.php", {
fullname: $("#fullname").val(),
uploadcv: $("#uploadcv").val()},
function(data){ });
PHP:
$name_of_uploaded_file = basename($_FILES['uploadcv']['name']);
$type_of_uploaded_file =
substr($name_of_uploaded_file,
strrpos($name_of_uploaded_file, '.') + 1);
$size_of_uploaded_file = $_FILES["uploadcv"]["size"]/1024;//size in KBs
$max_allowed_file_size = 100; // size in KB
$allowed_extensions = array("jpg", "jpeg", "gif", "bmp", 'doc', 'docx', 'pdf');
$upload_folder = 'cv/'; //<-- this folder must be writeable by the script
$path_of_uploaded_file = $upload_folder . $name_of_uploaded_file;
$tmp_path = $_FILES["uploadcv"]["tmp_name"];
if(is_uploaded_file($tmp_path)) {
if(!copy($tmp_path,$path_of_uploaded_file)) {
echo '\n error while copying the uploaded file';
}
}