PHP上传器和下载器文件大小限制

时间:2016-11-21 15:54:57

标签: php cordova phonegap-plugins file-transfer

我有一个上传php脚本,用随机名称将文件上传到我的服务器(没有扩展名)

<?php header('Access-Control-Allow-Origin: *');
    //Read parameters
    $documentuniqueid = addslashes($_REQUEST['did']);

    //Get file name
    $filename = urldecode($_FILES["file"]["name"]);

    //Move file to folder
    move_uploaded_file($_FILES["file"]["tmp_name"], "docs/".$documentuniqueid);
?>

我可以从我的iPhone上传图像而没有任何错误(通过PhoneGap应用程序,使用FileTransfer插件),但当我将该文件下载到我的桌​​面时,添加&#34; .jpg&#34;扩展到它,图像将被破坏(其中有随机的垂直线)

另外,为了下载,我使用以下PHP脚本:

<?php
    ...reading parameters...
    $original_filename = "http://www.example.com/docs/".$document_id;
    $new_filename = $real_document_name;    

    //Complex header (NOT USED, but I also tried this, where the content-type is specified exactly for JPGs
    //headers to send your file
    //header("Content-Type: application/jpeg");
    //header("Content-Length: " . filesize($original_filename));
    //header('Content-Disposition: attachment; filename="' . $new_filename . '"');      

    //Second one
    $finfo = finfo_open(FILEINFO_MIME_TYPE);
    header('Content-Type: '.finfo_file($finfo, $original_filename));
    header("Content-Length: " . filesize($original_filename));
    header('Content-disposition: attachment; filename="'.$new_filename.'"');      

    //clean up
    ob_clean();
    flush();

    readfile($original_filename);          
    exit();
?>

适用于大约700 KB的文件,但是对于我的iPhone 4MB的文件,它不再起作用。

我应该在某处指定最大文件大小吗?

0 个答案:

没有答案