我正在尝试上传到特定文件夹的php上传。 可以选择他们希望上传到文件夹列表下拉框旁边的文件。这是因为它组织文件。
<?php
session_start();
if(!isset($_SESSION["USER"]["Admin"])){
header("Location: index.html?unath");
}
$folder = mysql_real_escape_string($_POST['loc']);
$target_path = "../../shared/docs/$folder";
$upload2 = $target_path . basename( $_FILES['uploadedfile']['name']);
if(move_uploaded_file($_FILES['uploadedfile']['tmp_name'], $upload2)) {
echo "The file ". basename( $_FILES['uploadedfile']['name']).
" has been uploaded";
} else{
echo "There was an error uploading the file, please try again!";
}
?>
目前,代码将文件上传到“docs”文件夹而不是docs /文件夹。相反,它将文件夹名称放在文件的前面。例如 - 如果文件夹名为“abc”而我的文件名为robs.docx,则会将其上传到主Docs文件夹并将其命名为abcrobs.docx
答案 0 :(得分:2)
你缺少斜杠
替换此行:
$upload2 = $target_path . basename( $_FILES['uploadedfile']['name']);
使用:
$upload2 = $target_path ."/". basename( $_FILES['uploadedfile']['name']);
OR:
替换此行:
$target_path = "../../shared/docs/$folder";
使用:
$target_path = "../../shared/docs/".$folder."/";
答案 1 :(得分:1)
mysql_real_escape_string
,因为此处不涉及SQL。mysql_real_escape_string
将返回null
。所以你可能会丢掉$_POST['loc']
值。var_dump
来查看各个阶段的值,并进行一些调试。答案 2 :(得分:0)
$ target_path
后缺少斜杠答案 3 :(得分:0)
在/
:
$target_path
$target_path = "../../shared/docs/$folder/";
答案 4 :(得分:0)
你 应该正确地转义你的变量:
$target_path = "../../shared/docs/". $folder ."/";