0

我正在尝试使用 Xhr sendAsBinary 将二进制数据发送到服务器。当我从本地主机测试它时,它没有故障。但是当它从我的共享主机服务器测试时,我得到了这个响应

<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">
<html><head>
<title>403 Forbidden</title>
</head><body>
<h1>Forbidden</h1>
<p>You don't have permission to access /mvc/control/upload.php
on this server.</p>
<p>Additionally, a 404 Not Found
error was encountered while trying to use an ErrorDocument to handle the request.</p>
</body></html>

它从同一个域发送请求,当我检查错误日志时,我得到以下信息

PHP Warning:  PHP Startup: Unable to load dynamic library '/usr/local/lib/php/extensions/no-debug-non-zts-20090626/timezonedb.so' - /usr/local/lib/php/extensions/no-debug-non-zts-20090626/timezonedb.so: cannot open shared object file: No such file or directory in Unknown on line 0

我想也许问题出在我的 php 文件上,所以使用另一个 url 指向不同的文件,它给了我同样的错误,我什至尝试输入一个不存在的文件路径,它只是给了我同样的错误。我的 js 看起来像这样

function upload(file,json_content,callback,prog,path)
{
var reader = new FileReader();
reader.readAsBinaryString(file); // alternatively you can use readAsDataURL
var jc = JSON.stringify(json_content);// turning the json object to a string so that it be written to array buffer as binary
var jc_size = jc.length;//the length of the stringified json object
reader.onload  = function(evt)
{
    xhr = new XMLHttpRequest();
    // send the file through POST
    xhr.open("POST", path, true);
    // make sure we have the sendAsBinary method on all browsers
    XMLHttpRequest.prototype.mySendAsBinary = function(text)
    {
        var f_size = text.length;
        var data = new ArrayBuffer(f_size+4+jc_size); //the length of the file plus the 1 byte code
        var ui32a = new Uint32Array(data,0,1);
        var ui8a = new Uint8Array(data,4,f_size);
        var ui8_jsn = new Uint8Array(data,4+f_size,jc_size);
        ui32a[0] = (f_size)& 0xffffffff;
        var test = new Uint8Array(data,0,4);

        for (var i = 0; i < f_size; i++) 
        {
            ui8a[i] = (text.charCodeAt(i) & 0xff);
        }
        for (var i = 0; i < jc_size; i++) 
        {
            ui8_jsn[i] = (jc.charCodeAt(i) & 0xff);
        }
        if(typeof window.Blob == "function")
        {
            var blob = new Blob([data]);
        }else
        {
            var bb = new (window.MozBlobBuilder || window.WebKitBlobBuilder || window.BlobBuilder)();
            bb.append(data);
            var blob = bb.getBlob();
        }

    this.send(blob);
    }
    if(prog !== false) /*if progress is needed*/
    {
        // tracking upload progress
         var eventSource = xhr.upload || xhr;
         eventSource.addEventListener("progress", function(e)
         {
         // get percentage of how much of the current file has been sent
         var position = e.position || e.loaded;
         var total = e.totalSize || e.total;
         progress = "#" + prog;
         $(progress).attr('max', total);
                        var percentage = Math.round((position/total)*100);

                        $(progress).css('width', percentage+"%").html(percentage+"%");
          });
     }

     // state change observer - after successfull upload..thentyu
     xhr.onreadystatechange = function()
      {
          if(xhr.readyState == 4)
          {

            if(xhr.status == 200)
            {

                callback(xhr.response);                                 

            }else{
                                // process error
                 }
             }
         };

                    // start sending
        xhr.mySendAsBinary(evt.target.result);
            };
        }

任何帮助将不胜感激,我尝试联系网络主机,但他们似乎一无所知

4

0 回答 0