我正在将Fine-Uploader与 PHP 一起使用,但发生了一些错误。当我在后端使用 stream_copy_to_stream() 时,它总是返回 0。
这是我在后端的代码:
private function upload_file($file_name, $tmp_name)
{
$result = array(
'is_successful' => true,
'extra_message' => ''
);
$target_path = $this->get_target_file_path($file_name, $tmp_name);
move_uploaded_file($tmp_name, $target_path);
$result['is_successful'] = $this->handle_upload_request($target_path);
if ( $result['is_successful'] ) {
$result['extra_message'] = $target_path;
} else {
$result['extra_message'] = 'Unknown error occured.<br />';
}
return $result;
}
private function handle_upload_request($path)
{
$input = fopen("php://input", "r");
$temp = tmpfile();
$real_size = stream_copy_to_stream($input, $temp);
fclose($input);
echo $real_size;
if ($real_size != $this->get_size()){
return false;
}
$target = fopen($path, "w");
fseek($temp, 0, SEEK_SET);
stream_copy_to_stream($temp, $target);
fclose($target);
return true;
}
但是,$real_size 始终等于 0。奇怪的是,文件有时可以成功上传,但有时不能。
我想这可能是由于Linux中的许可。因为我发现上传文件的时候,文件的mod是644(但我觉得644就够了)。而且这个问题在Windows中也存在。
它出什么问题了?