有趣的问题我似乎遇到过。我有一个表单上传图像并将其存储在数据库表中。表单上传图像文件OK并使其可用于处理。问题如下:使用move_uploaded_file到指定的目录不起作用,但是使用copy()
到这个目录呢。PHP move_uploaded_file/copy issue
的代码当前如下:
$file = $_FILES['doc_path'];
$ext = array_pop(explode('.', $file['name']));
$filename = uniqid() . '.' . $ext;
if ($file['error'] == UPLOAD_ERR_NO_FILE && ! strlen($this->filename)) {
throw new Exception('Please select a file to upload');
} elseif ($file['error'] == UPLOAD_ERR_NO_FILE) {
return true; // already have a file
} elseif ($file['error']) {
throw new Exception('File upload error');
} elseif (! $file['size']) {
throw new Exception('File is of zero length');
} else {
$path = 'uploads/' . $filename;
if (! move_uploaded_file($file['tmp_name'], $path)) {
throw new Exception('Could not upload file');
}
return $filename;
}
我已经检查目标目录存在,并且该目录是可写的。使用move_uploaded_file()不会产生错误,只会捕获“无法上传文件”异常。
本来想过如果这是一个权限问题,那么用move_uploaded_file
代替copy
就行不通了?
你有没有得到这个修复?我有同样的问题。 – Scott 2011-07-21 16:04:45
oops,没有扩展下面的评论线程。我找到了print_r($ _ FILES);对我非常有帮助。谢谢。 – Scott 2011-07-21 17:27:32