2012-11-13 30 views
0

我有一個程序,用來接受來自用戶的圖像。我改變它接受PDF文件,而不是我們的客戶要求的問題是不起作用。PDF上傳不起作用,但其他擴展工程

我已經改變了這個

'pdf' => array('application/pdf', 'application/x-pdf', 'application/x-download','application/download','binary/octet-stream'), 

我mimes.php配置這是我保存上傳的文件

$config = array(
'upload_path' => 'news', 
'allowed_types' => 'pdf', 
'max_size' => '10000000', 
); 
$this->load->library('upload', $config); 
$this->upload->do_upload('userfile'); 
$data = $this->upload->data(); 
echo json_encode(array('data' => $data)); 

HTML

<form id="imgadd-form" method="post" accept-charset="utf-8" enctype="multipart/form-data"> 
    Upload :<br> 
    <input type="file" name="userfile" id="userfile"> 
</form> 

jQuery的

function uploadfile() 
{ 
$.ajaxFileUpload({ 
    url  : 'save_data/uploadfile/', 
    secureuri : false , 
    fileElementId : 'userfile' , 
    dataType : 'json' , 
    success  : function(data , status) { 
     if (status != 'error'){//&& data.data.is_image) { 
      sysAlert('File Successfully Uploaded'); 
     } 
     else 
      sysAlert('Error Uploading'); 
    } 
}); 
} 
CI碼

編輯: 該文件正在由jquery報告上傳成功,因爲它返回的JSON,但每當我檢查目錄,什麼都沒有。 奇怪的是,我將文件擴展名重命名爲.TXT,並上傳了帶有.txt擴展名的3.5MB pdf文件,並且成功上傳並位於正確的目錄中。

編輯: 的var_dump的$ _FILES

"array(1) { 
    ["userfile"]=> 
    array(5) { 
    ["name"]=> string(8) "test.pdf" 
    ["type"]=> string(24) "application/octet-stream" 
    ["tmp_name"]=>string(24) "C:\xampp\tmp\phpF84F.tmp" 
    ["error"]=>int(0) 
    ["size"]=>int(3748991) 
    } 
} 

回聲$這 - > upload->的display_errors();

<p>The filetype you are attempting to upload is not allowed.</p> 

更新: 改變 '的max_size'

'max_size'  => '10000000', 

CI版本2.1.2是

+0

你確定你設置了足夠多的'upload_max_filesize'和'post_max_size'嗎? – Serg

+0

@Serg我檢查了phpinfo(); 'upload_max_filesize 128M'和'post_max_size 8M' – MegaNairda

+0

你能檢查$ _FILE變量嗎?製作一個var_dump並查看它的內容,也許你可以找到缺失的東西! –

回答

1

Mimes.php

'pdf' => array('application/pdf', 'application/x-download') 

CI代碼:

$config['upload_path'] = '$path'; 
       $config['allowed_types'] = 'pdf'; 
       $config['max_size']  = '4096';  
       $config['overwrite']  = TRUE; 

       $this->load->library('upload', $config); 
       $this->upload->display_errors('', ''); 

       if (!$this->upload->do_upload("csv_file")) { 
         echo $this->upload->display_errors(); die(); 
         $this->data['error'] = array('error' => $this->upload->display_errors()); 
       } else { 
        $upload_result = $this->upload->data(); 
       } 
+0

它是奇怪的,只有Firefox認爲pdf文件格式'應用程序/ x下載' –

相關問題