上传文件时遇到问题。 当我在目录中使用变量时, php制作一个重复的文件:一个在正确的目录中,另一个在变量前的目录中。 这是我写的代码
$ext = $_POST["ext"];
$evnm = $_POST["evnm"];
$uploaddir = '../../../media/';
if (!file_exists($uploaddir)) {
mkdir($uploaddir, 0777, true);
}
$uploaddir .= $evnm.'/';
if (!file_exists($uploaddir)) {
mkdir($uploaddir, 0777, true);
}
$uploaddir .= $ext.'/';
if (!file_exists($uploaddir)) {
mkdir($uploaddir, 0777, true);
}
$fl = $_FILES["file"];
foreach($fl["name"] as $key=>$name){
$tmp_name = $fl["tmp_name"][$key];
$targetFile = $uploaddir.$name;
$files[] = $targetFile;
if(!file_exists($targetFile)){
if(move_uploaded_file($tmp_name, $targetFile)){
$MSG = "Media file uploaded successfully<br>";
$tst = true;
}else{
$MSG = "Media file failed uploding<br>";
$tst = false;
}
}else{
$MSG = 'Media file already exists<br>';
$tst = false;
$exst = true;
}
}
`