flowjs / flow-php-server

flow.js php server library, validates uploaded chunks and safely merges all chunks to a single file
http://flowjs.github.io/ng-flow/
MIT License
245 stars 42 forks source link

Error if print_f($file) or print_f($request) is not in code #28

Closed FragginWagon closed 8 years ago

FragginWagon commented 8 years ago

Need thoughts on this:

            $request = new \Flow\Request();

    $config = new \Flow\Config();

    $config->setTempDir('./');

    $file = new \Flow\File($config, $request);

    if ($_SERVER['REQUEST_METHOD'] === 'GET') {
        if ($file->checkChunk()) {
            header("HTTP/1.1 200 Ok");
        } else {
            header("HTTP/1.1 204 No Content");
            return ;
        }
    } else {
    //print_r($file); // -> UNCOMMENTING THIS MAKES THIS CALL WORK...
      if ($file->validateChunk()) {
          $file->saveChunk();
      } else {
          // error, invalid chunk upload request, retry
          header("HTTP/1.1 400 Bad Request");
          return ;
      }
    }
    if ($file->validateFile() && $file->save($request->getFileName())) {
        // File upload was completed
    } else {
        // This is not a final chunk, continue to upload
    }

FragginWagon commented 8 years ago

Forgot to mention, this is what the message is and where it fails:

Remote Address:127.0.0.1:80 Request URL:http://ov-api.dev/public/webupload Request Method:OPTIONS Status Code:400 Bad Request Response Headers view source Access-Control-Allow-Headers:Origin, X-Requested-With, Content-Type, Accept Access-Control-Allow-Methods:GET, PUT, POST, DELETE, OPTIONS Access-Control-Allow-Origin:* Cache-Control:no-store, no-cache, must-revalidate, post-check=0, pre-check=0 Connection:close Content-Length:0 Content-Type:text/html Date:Fri, 27 Nov 2015 01:28:21 GMT Expires:Thu, 19 Nov 1981 08:52:00 GMT Pragma:no-cache Server:Apache/2.4.16 (Unix) PHP/5.5.29 Set-Cookie:PHPSESSID=720ebe806d075ca92a8ccca7235d21f3; path=/ X-Powered-By:PHP/5.5.29 Request Headers view source Accept:/ Accept-Encoding:gzip, deflate, sdch Accept-Language:en-US,en;q=0.8 Access-Control-Request-Headers:content-type Access-Control-Request-Method:POST Cache-Control:no-cache Connection:keep-alive Host:ov-api.dev Origin:http://gastrotrack.dev Pragma:no-cache Referer:http://gastrotrack.dev/ User-Agent:Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/46.0.2490.86 Safari/537.36

AidasK commented 8 years ago

I think you should also check if request method is OPTIONS and return 200 status code if it is.