PHP dosya yükleme jquery

0 Cevap php

Ive got contact form with PHP and jquery. Everything works fine except the upload file. its not uploaded to the folder. if i put the PHP code in the same page as html page, the upload file works fine?

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';
      }
    }

0 Cevap