Вопрос

this is my ajax code:

$(function(){
    var cntUp = 0;
    var btnUpload=$('#upload_pdf');
    var status=$('#status');

    new AjaxUpload(btnUpload, {
        action: 'uplod_estimate_file.php',
        data: {saleid: $("#hid_saleid").val()},
        name: 'uploadfile_test',
        onSubmit: function(file, ext){
             if (! (ext && /^(jpg|pdf|jpeg)$/.test(ext))){ 
                // extension is not allowed 
                alert('Only JPG, PDF or JPEG files are allowed');
                return false;
            }
            this.setData({
                'saleid': $("#hid_saleid").val()
            });

            status.text('Uploading...');
        },
        onComplete: function(file, response){
            if (response.toLowerCase().indexOf("success") >= 0 ) {
                alert(response);
                /*
                var image='<img src="uploads/'+saleid+'/'+fname+'" alt=""  width="131px" height="125px"/>';
                $("#img0").html(image);*/

            }  else{
                $('<li></li>').appendTo('#files').text(file).addClass('error');
                //alert('error');
            }
        }
    });

});

this is the form:

<form name="frmvehdetails" id="frmvehdetails" method="post">

        <table cellpadding="3">
                  <tr>
            <td valign="top">VIN</td>
            <td>

                      <input class="frmIn" size="30"  name="car-vin" id="car-vin" type="text" value="" />
                      <input onclick="lookupVIN()" name="btnVin" type="button" value="Lookup" />
                      <br/>
                      <div id="vinDet" style="line-height: 20px; margin-bottom: 10px; margin-top: 10px;"></div></td>
          </tr>
                  <tr>
            <td>Year</td>
            <td><select name="car-years" id="car-years">
              </select></td>
          </tr>
                  <tr>
            <td>Make</td>
            <td><select name="car-makes" id="car-makes">
              </select></td>
          </tr>
                  <tr>
            <td>Model</td>
            <td><select name="car-models" id="car-models">
              </select></td>
          </tr>
          <tr>
            <td>Milage</td>
            <td><input type="text" name="car-milage" id="car-milage" value="" class="frmIn" /></td>
          </tr>

             <tr>
            <td>Repair Estimate</td>
            <td><input type="text" value="" id="car_estimate" name="car_estimate" class="frmIn"></td>
          </tr>
          <tr>
            <td>&nbsp;</td>
            <td><div id="upload_pdf" style="margin-bottom:10px;" >
                  <span>Upload File</span></div></td>
          </tr>


          <tr>
            <td>Reserve Price</td>
            <td><input type="text" value="" id="car_reserve" name="car_reserve" class="frmIn"></td>
          </tr>
                  <tr>
            <td>&nbsp;</td>
            <td>
                      <input type="button"  name="sub" value="<< Previous " class="previous-product" />
                     <input type="button" id="sub" name="sub" value="Next >>" class="next-product" onclick="validatevehicle();" /></td>
          </tr> <tr>
            <td>&nbsp;</td>
             <td id="v_errmsgs" style="color:red">
           </td>
          </tr>
                </table></form>
                <input type="hidden" id="hid_saleid" name="hid_saleid" value="" />

This is the uplod_estimate_file.php:

<?php
session_start();
$sub = "";
$uploaddir = "";
if(isset($_POST['saleid'])){
    if($_POST['saleid']){
        $sub = $_POST['saleid'];
    }else{
        $sub = "";
    }
}else{
    $sub = "";
}
if($sub){
    $uploaddir = './uploads/'.$sub."/"; 
    }else{
        $uploaddir = './uploads/';
    }
$file = $uploaddir . basename($_FILES['uploadfile_test']['name']); 

if(move_uploaded_file($_FILES['uploadfile_test']['tmp_name'], $file)){
    echo "success";
}else{
    echo "error";
}


?>

But when i using this i got error undefined index 'uploadfile_test'.How can i solve this?

Это было полезно?

Решение

if its problem with uppercase extension, like "PDF", then change:

onSubmit: function(file, ext){
   if (! (ext && /^(jpg|pdf|jpeg)$/.test(ext))){

to

onSubmit: function(file, ext){
   if (! (ext && /^(jpg|pdf|jpeg|pdf)$/i.test(ext))){ 

You can add "upload_max_filesize" to .htaccess, like:

php_value upload_max_filesize 32M
Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top