我正在尝试使用此PHP脚本将文件上传到动态创建的目录,但没有bueno。如果我只设置$storeFolder = 'uploads';
,但是不会将它们移动到我的新文件夹,该脚本会有效。我已尝试手动创建文件夹,即使(eek)权限设置为777.即使是骰子也没有。
<?php
$ds = DIRECTORY_SEPARATOR;
function curPageURL()
{
$pageURL = 'http';
if (isset($_SERVER["HTTPS"]) && strtolower($_SERVER["HTTPS"]) == "on") {
$pageURL .= "s";
}
$pageURL .= "://";
if ($_SERVER["SERVER_PORT"] != "80") {
$pageURL .= $_SERVER["SERVER_NAME"] . ":" . $_SERVER["SERVER_PORT"] . $_SERVER["REQUEST_URI"];
} else {
$pageURL .= $_SERVER["SERVER_NAME"] . $_SERVER["REQUEST_URI"];
}
return $pageURL;
}
$murl = curPageURL();
parse_str($murl, $result);
$storeFolder = 'uploads' . $ds . $result['f'];
if (!is_dir($storeFolder)) {
mkdir($storeFolder, 775);
}
if (!empty($_FILES)) {
$tempFile = $_FILES['file']['tmp_name'];
$targetPath = dirname(__FILE__) . $ds . $storeFolder . $ds;
$targetFile = $targetPath . $_FILES['file']['name'];
move_uploaded_file($tempFile, $targetFile);
}
?>
答案 0 :(得分:5)
您错过了零mkdir($storeFolder, 0775);
手册http://php.net/manual/en/function.mkdir.php声明:
bool mkdir(string $ pathname [,int $ mode = 0777 [,bool $ recursive = false [,resource $ context]]])