我需要帮助来解决此问题文件未在动态创建的文件夹/子文件夹中上传!
使用subfolder
创建动态input type text
,当我上传的文件移至uploads folders
但未移至使用subfolder
但动态创建功能正常工作,并向我显示文件夹中输入上传文件夹的文件夹
这里是我的代码
//creating dynamically subfolders
$folder = $_POST['folder'];
foreach( $folder as $key => $value){
$dirPath = 'uploads/'.$value;
$result = mkdir($dirPath);
}
if ($result == '1') {
//file move on function
$target_path = 'uploads/'.$results;
$target_path = $target_path . basename( $_FILES['uploadedfile']['name']);
if(move_uploaded_file($_FILES['uploadedfile']['tmp_name'], $target_path)) {
echo "The file ". basename( $_FILES['uploadedfile']['name']).
" has been uploaded";
} else{
echo "There was an error uploading the file, please try again!";
}
} else {
echo $dirPath . " has NOT been created";
}
}
<form method="post" enctype="multipart/form-data">
<input name="uploadedfile" type="file" /><br />
<input type="text" id="folder" name="folder"><br />
<input type="submit" name="test" value="Upload File" />
</form>
我的问题现在解决了我已经完成了我的脚本
//creating a folder
$folder = $_POST['folder'];
$dirPath = 'uploads/'.$folder;
$result = mkdir($dirPath);
if ($result == '1') {
//file move on
$target_path = $dirPath .'/' . basename( $_FILES['uploadedfile']['name']);
if(move_uploaded_file($_FILES['uploadedfile']['tmp_name'], $target_path)) {
echo "The file ". basename( $_FILES['uploadedfile']['name']).
" has been uploaded";
} else{
echo "There was an error uploading the file, please try again!";
}
} else {
echo $dirPath . " has NOT been created";
}
}
答案 0 :(得分:1)
试试这个,
替换
$target_path = 'uploads/'.$results;
到
$target_path = $dirPath.'/';
否则,
$target_path = $dirPath .'/'. basename( $_FILES['uploadedfile']['name']);
if(move_uploaded_file($_FILES['uploadedfile']['tmp_name'], $target_path)) {
echo "The file ". basename( $_FILES['uploadedfile']['name']). " has been uploaded";
}
答案 1 :(得分:0)
$结果定义在哪里?你在这里使用它:
$target_path = 'uploads/'.$results;
为什么?
另外,$ result是mkdir()的真或假返回,所以你也不能使用那个。