我有一个脚本,允许用户在我的网站上传图片和视频。我需要查看它们,如何设置适当的权限?
chmod("upload/" . $_FILES["file"]["name"], 0755)
这不起作用,我希望我可以在Windows中使用这些文件,因为我需要处理它。我该怎么办?
答案 0 :(得分:0)
您不需要设置PHP上传的文件的chmod,因为Web服务器已经“拥有”该文件。
处理档案
要在浏览器中查看它,您需要确保将文件从临时目录移动到上载目录,其内容类似于以下内容:
// Define where the uploads directory is
$upload_dir = '/var/www/uploads/';
// Define the upload path from $upload_dir
$upload_file = $upload_dir . basename($_FILES['file']['name']);
// Move the tmp uploaded file to the uploads directory
if( !move_uploaded_file($_FILES['file']['tmp_name'], $upload_file) ) {
// Handle the failure to move the temp file
echo "File did not upload";
};
您可以通过var转储路径或检查文件是否存在来检查文件是否已移动到适当的位置。
// Is path correct?
var_dump($upload_file);
// Did the file get moved?
var_dump(file_exists($upload_file));
还有问题吗?
如果文件没有上传到服务器,则可能存在几个问题。请参阅此PHP文档page on uploads pitfalls。总结:
在php.ini中查看这些内容,并根据需要增加其值以供选择。
要检查的另一个选项是,由于 .htaccess 文件mod重写,上传目录未被阻止提供图像。