我想上传到目录“上传”,这是根目录上方的一步(使用Plesk)。
有人能告诉我为什么文件不会上传吗?权限已经上传为777。
ob_start();
session_start();
$extensions = array("jpg", "png","jpeg", "gif", "zip", "rar", "swf", "tiff", "bmp", "txt", "fla", "7z", "tar", "gz", "iso",
"dmg", "mp3", "wav", "m4a", "aac", "doc", "docx", "xls", "rtf", "ppt", "bsd", "exe", "psd", "c4d", "pdf", "dwg", "max", "ipa",
"vtf", "iam", "ipt", "flv", "cap", "scr");
$maxsize = 104288000;
$server = "http://www.andre.com";
$name = $_FILES['file']['name'];
$temp = $_FILES['file']['tmp_name'];
$size = $_FILES['file']['size'];
$random = md5(uniqid(rand(), true));
$random = substr($random, 0, 20);
if (!$name || !$temp || !$size)
{
echo "Go back and select a file.";
exit();
}
foreach ($_FILES as $file)
{
if ($file['tmp_name'] != null)
{
$thisext1=explode(".", strtolower($file['name']));
$thisext=$thisext1[count($thisext1)-1];
if (!in_array($thisext, $extensions))
{
echo "That file type is not allowed.";
exit();
}
}
}
if ($size > $maxsize)
{
echo "File size too big.";
exit();
}
$destination = "../Uploads/" . $random ;
mkdir($destination);
move_uploaded_file($temp, $destination."/".$name);
$final = $server."/".$destination."/".$name;
看着
$destination = "../Uploads/" . $random ;
特别是/var/www/vhosts/example.com/Uploads
。
答案 0 :(得分:1)
可以是open_basedir
或safe_mode
限制,也可以检查用户权限
答案 1 :(得分:0)
如果您尝试从根目录上传到上传,则不要使用../Uploads/来引用该目录。它是./Uploads/,或者只是上传/.
../引用当前目录上面的目录,在你的情况下是/ var / www / vhosts /.
答案 2 :(得分:0)
尝试使用$_SERVER['DOCUMENT_ROOT']
锚定您的相对路径:
$destination = $_SERVER["DOCUMENT_ROOT"] . "/../Uploads/" . $random;
或者,您可以使用__DIR__
使用相对于当前PHP脚本的路径(如果您使用的是PHP,则使用dirname(__FILE__)
):
$destination = __DIR__ . "/../Uploads/" . $random;
答案 3 :(得分:0)
我有一个open_basedir错误,因为user973 ...建议。
通过在
中创建vhost.conf来解决/var/www/vhosts/site.com/conf
在以下内容中添加:
<Directory /var/www/vhosts/site.com/httpdocs/>
php_admin_value open_basedir "/var/www/vhosts/uploadvillage.com/httpdocs:/tmp:/var/www/vhosts/site.com/Uploads"
</Directory>
然后使用:
重建apache配置[root@server1 ~]# /usr/local/psa/admin/bin/httpdmng --reconfigure-all