0

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';
      }
    }
1
  • If you'd like us to close this for you, flag it specifically for that. Commented Apr 30, 2011 at 16:01

2 Answers 2

1

I don´t think you can upload files like that using jquery. However, it seems you can use the jQuery Form Plugin to upload files but I haven´t tried it yet.

Sign up to request clarification or add additional context in comments.

Comments

0

Make sure that cv folder is in your root directory:

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.