2017-04-17 56 views
0

我试图在Manually Trigger Uploads & Edit File Names演示我的网站上实施和一切都很正常,但是当我尝试上传的文件我得到了在控制台下面:精细上传Bitnami wampstack上传失败

responseText = {"error":"Server error. Uploads directory isn't writable","uploadName":null}

我已经搜索了其他类似的问题,但他们似乎都没有为我工作,其中一些回答谈论{成功:真正},但我不明白他们的意思或在哪里设置,我认为并不重要,因为在演示代码没有成功:真实的属性。

我也试着设置在这里我要上传的图片(这是/项目根/ tmp)中使用此命令的文件夹权限:cacls apache2\htdocs\project\tmp /t /e /g everyone:f,但没有奏效。该插件非常好,但我认为他们应该在文档中添加更多示例。任何帮助,将不胜感激。

这里是我的模板:

 <div class="qq-uploader-selector qq-uploader" qq-drop-area-text="Drop files here"> 
     <div class="qq-total-progress-bar-container-selector qq-total-progress-bar-container"> 
      <div role="progressbar" aria-valuenow="0" aria-valuemin="0" aria-valuemax="100" class="qq-total-progress-bar-selector qq-progress-bar qq-total-progress-bar"></div> 
     </div> 
     <div class="qq-upload-drop-area-selector qq-upload-drop-area" qq-hide-dropzone> 
      <span class="qq-upload-drop-area-text-selector"></span> 
     </div> 
     <div class="buttons"> 
      <div class="qq-upload-button-selector qq-upload-button"> 
       <div>Select files</div> 
      </div> 
     </div> 
     <span class="qq-drop-processing-selector qq-drop-processing"> 
      <span>Processing dropped files...</span> 
      <span class="qq-drop-processing-spinner-selector qq-drop-processing-spinner"></span> 
     </span> 
     <ul class="qq-upload-list-selector qq-upload-list" aria-live="polite" aria-relevant="additions removals"> 
      <li> 
       <div class="qq-progress-bar-container-selector"> 
        <div role="progressbar" aria-valuenow="0" aria-valuemin="0" aria-valuemax="100" class="qq-progress-bar-selector qq-progress-bar"></div> 
       </div> 
       <span class="qq-upload-spinner-selector qq-upload-spinner"></span> 
       <img class="qq-thumbnail-selector" qq-max-size="100" qq-server-scale> 
       <span class="qq-upload-file-selector qq-upload-file"></span> 
       <span class="qq-edit-filename-icon-selector qq-edit-filename-icon" aria-label="Edit filename"></span> 
       <input class="qq-edit-filename-selector qq-edit-filename" tabindex="0" type="text"> 
       <span class="qq-upload-size-selector qq-upload-size"></span> 
       <button type="button" class="qq-btn qq-upload-cancel-selector qq-upload-cancel">Cancel</button> 
       <button type="button" class="qq-btn qq-upload-retry-selector qq-upload-retry">Retry</button> 
       <button type="button" class="qq-btn qq-upload-delete-selector qq-upload-delete">Delete</button> 
       <span role="status" class="qq-upload-status-text-selector qq-upload-status-text"></span> 
      </li> 
     </ul> 

     <dialog class="qq-alert-dialog-selector"> 
      <div class="qq-dialog-message-selector"></div> 
      <div class="qq-dialog-buttons"> 
       <button type="button" class="qq-cancel-button-selector">Close</button> 
      </div> 
     </dialog> 

     <dialog class="qq-confirm-dialog-selector"> 
      <div class="qq-dialog-message-selector"></div> 
      <div class="qq-dialog-buttons"> 
       <button type="button" class="qq-cancel-button-selector">No</button> 
       <button type="button" class="qq-ok-button-selector">Yes</button> 
      </div> 
     </dialog> 

     <dialog class="qq-prompt-dialog-selector"> 
      <div class="qq-dialog-message-selector"></div> 
      <input type="text"> 
      <div class="qq-dialog-buttons"> 
       <button type="button" class="qq-cancel-button-selector">Cancel</button> 
       <button type="button" class="qq-ok-button-selector">Ok</button> 
      </div> 
     </dialog> 
    </div> 

我的javascript:

var manualUploader = new qq.FineUploader({ 
    element: document.getElementById('fine-uploader-manual-trigger'), 
    template: 'qq-template-manual-trigger', 
    request: { 
     endpoint: ''+ENDPOINT.path+'/endpoint.php' 
    }, 
    autoUpload: true, 
    debug: true 
}); 

和我endpoint.php(这几乎是相同的official github的):

<?php 

/** 
* PHP Server-Side Example for Fine Uploader (traditional endpoint handler). 
* Maintained by Widen Enterprises. 
* 
* This example: 
* - handles chunked and non-chunked requests 
* - supports the concurrent chunking feature 
* - assumes all upload requests are multipart encoded 
* - supports the delete file feature 
* 
* Follow these steps to get up and running with Fine Uploader in a PHP environment: 
* 
* 1. Setup your client-side code, as documented on http://docs.fineuploader.com. 
* 
* 2. Copy this file and handler.php to your server. 
* 
* 3. Ensure your php.ini file contains appropriate values for 
* max_input_time, upload_max_filesize and post_max_size. 
* 
* 4. Ensure your "chunks" and "files" folders exist and are writable. 
* "chunks" is only needed if you have enabled the chunking feature client-side. 
* 
* 5. If you have chunking enabled in Fine Uploader, you MUST set a value for the `chunking.success.endpoint` option. 
* This will be called by Fine Uploader when all chunks for a file have been successfully uploaded, triggering the 
* PHP server to combine all parts into one file. This is particularly useful for the concurrent chunking feature, 
* but is now required in all cases if you are making use of this PHP example. 
*/ 

// Include the upload handler class 
require_once "handler.php"; 


$uploader = new UploadHandler(); 

// Specify the list of valid extensions, ex. array("jpeg", "xml", "bmp") 
$uploader->allowedExtensions = array(); // all files types allowed by default 

// Specify max file size in bytes. 
$uploader->sizeLimit = null; 

// Specify the input name set in the javascript. 
$uploader->inputName = "qqfile"; // matches Fine Uploader's default inputName value by default 

// If you want to use the chunking/resume feature, specify the folder to temporarily save parts. 
$uploader->chunksFolder = "chunks"; 

$method = get_request_method(); 

// This will retrieve the "intended" request method. Normally, this is the 
// actual method of the request. Sometimes, though, the intended request method 
// must be hidden in the parameters of the request. For example, when attempting to 
// delete a file using a POST request. In that case, "DELETE" will be sent along with 
// the request in a "_method" parameter. 
function get_request_method() { 
    global $HTTP_RAW_POST_DATA; 

    if(isset($HTTP_RAW_POST_DATA)) { 
     parse_str($HTTP_RAW_POST_DATA, $_POST); 
    } 

    if (isset($_POST["_method"]) && $_POST["_method"] != null) { 
     return $_POST["_method"]; 
    } 

    return $_SERVER["REQUEST_METHOD"]; 
} 

if ($method == "POST") { 
    header("Content-Type: text/plain"); 

    // Assumes you have a chunking.success.endpoint set to point here with a query parameter of "done". 
    // For example: /myserver/handlers/endpoint.php?done 
    if (isset($_GET["done"])) { 
     $result = $uploader->combineChunks("files"); 
    } 
    // Handles upload requests 
    else { 

     // Call handleUpload() with the name of the folder, relative to PHP's getcwd() 
     $result = $uploader->handleUpload("tmp"); 

     // To return a name used for uploaded file you can use the following line. 
     $result["uploadName"] = $uploader->getUploadName(); 

    } 

    echo json_encode($result); 
} 
// for delete file requests 
else if ($method == "DELETE") { 
    $result = $uploader->handleDelete("files"); 
    echo json_encode($result); 
} 
else { 
    header("HTTP/1.0 405 Method Not Allowed"); 
} 

?> 

回答

0

的问题是文件夹的路径:

// Call handleUpload() with the name of the folder, relative to PHP's getcwd() 
     $result = $uploader->handleUpload("tmp") 

该评论说,这是相对于PHP的getcwd(),但是当我回显该函数时,它获取了根项目,因此最后文件夹路径相对于endpoint.php文件的位置。如果您遇到同样的问题,请注意文件夹路径。

这是我的工作endpoint.php:

<?php 

// Include the upload handler class 
require_once "handler.php"; 


$uploader = new UploadHandler(); 

// Specify the list of valid extensions, ex. array("jpeg", "xml", "bmp") 
$uploader->allowedExtensions = array(); // all files types allowed by default 

// Specify max file size in bytes. 
$uploader->sizeLimit = null; 

// Specify the input name set in the javascript. 
$uploader->inputName = "qqfile"; // matches Fine Uploader's default inputName value by default 

// If you want to use the chunking/resume feature, specify the folder to temporarily save parts. 
$uploader->chunksFolder = "../../uploads"; 

$method = get_request_method(); 

// This will retrieve the "intended" request method. Normally, this is the 
// actual method of the request. Sometimes, though, the intended request method 
// must be hidden in the parameters of the request. For example, when attempting to 
// delete a file using a POST request. In that case, "DELETE" will be sent along with 
// the request in a "_method" parameter. 
function get_request_method() { 
    global $HTTP_RAW_POST_DATA; 

    if(isset($HTTP_RAW_POST_DATA)) { 
     parse_str($HTTP_RAW_POST_DATA, $_POST); 
    } 

    if (isset($_POST["_method"]) && $_POST["_method"] != null) { 
     return $_POST["_method"]; 
    } 

    return $_SERVER["REQUEST_METHOD"]; 
} 

if ($method == "POST") { 
    header("Content-Type: text/plain"); 

    // Assumes you have a chunking.success.endpoint set to point here with a query parameter of "done". 
    // For example: /myserver/handlers/endpoint.php?done 
    if (isset($_GET["done"])) { 
     $result = $uploader->combineChunks("../../uploads"); 
    } 
    // Handles upload requests 
    else { 

     // Call handleUpload() with the name of the folder, relative to PHP's getcwd() 
     $result = $uploader->handleUpload("../../uploads"); //this folder was created in the root project, at the same level as wp-content 

     // To return a name used for uploaded file you can use the following line. 
     $result["uploadName"] = $uploader->getUploadName(); 

    } 

    echo json_encode($result); 
} 
// for delete file requests 
else if ($method == "DELETE") { 
    $result = $uploader->handleDelete("../../uploads"); 
    echo json_encode($result); 
} 
else { 
    header("HTTP/1.0 405 Method Not Allowed"); 
} 

?>