2

I'm using the Valums File Uploader to upload files using XHR. The script I use works great on my live server while it fails on my local server. The code concerned is following:

    $input = fopen("php://input", "r");   
    $temp = tmpfile();
    $realSize = stream_copy_to_stream($input, $temp);
    fclose($input);

    if ($realSize != $this->getSize()){            
        return false;
    }

    $target = fopen($path, "w");        
    fseek($temp, 0, SEEK_SET);
    stream_copy_to_stream($temp, $target);
    fclose($target);
    chmod($path, 0644);

The thing is that $realSize is empty on my local server while it does have a value on my live server. So on the local server it breaks at the size check. I suspect it is a server configuration issue, but I don't exactly know what to look for. Could someone point me into the right direction?

tvgemert
  • 1,436
  • 3
  • 25
  • 50
  • 1
    Are you certain that both `$input` and `$temp` are valid resources? – Matt Aug 23 '12 at 15:21
  • I'm not very familiar with `stream_copy_to_stream` but your code doesn't look anything like the example in the [manual](http://php.net/manual/en/function.stream-copy-to-stream.php). Doesn't `$temp` have to be the result of an `fopen()`? (Unless that's what `tmpfile()` does, of course.) – Matt Aug 23 '12 at 15:24
  • Hi Matt, it's a working piece of code from the Valums file uploader (http://valums.com/ajax-upload/). But you were right in questioning the validity of the resources $input and $temp. $temp seems to be empty so I'll take a look from that point. – tvgemert Aug 24 '12 at 07:57

1 Answers1

2

I've found the culprit. tmpfile() wasn't able to create the temp file because the rights on the temp folder didn't allow write. Found the location of the temp folder using sys_get_temp_dir() Made this directory writable and all was GO again!

tvgemert
  • 1,436
  • 3
  • 25
  • 50