因此,我正在写一个网站,该网站的功能是允许用户上传特定角色的图片。我已经编写了一些php代码,以便从表单中获取值,然后确定将图像放入其中的目录。
我正在使用Apache 2运行XAMPP,并且在运行代码时,先前输入的文件未放入目标文件夹中。并显示一条警告消息“文件未上传”,该消息已硬编码。
if($Character == "Bangalore"){
$target_dir = "/Characters/Bangalore/";
}
elseif($Character == "Blooudhound"){
$target_dir = "/Characters/Blooudhound/";
}
elseif($Character == "Caustic"){
$target_dir = "/Characters/Caustic/";
}
//(etc...)
elseif($Character == "Wraith"){
$target_dir = "/Characters/Wraith/";
}
else{
$target_dir = "/uploads/";
}
$target_file = $target_dir . basename($_FILES["fileToUpload"]["name"]);
$uploadOk = 1;
$imageFileType = strtolower(pathinfo($target_file,PATHINFO_EXTENSION));
//(etc...)
if (move_uploaded_file($_FILES["fileToUpload"]["tmp_name"], $target_file)) {
//Report if this was moved or not
这是php代码
<select name="Character">
<option value="Bangalore">Bangalore</option>
<option value="Bloodhound">Bloodhound</option>
<option value="Caustic">Caustic</option>
<option value="Gibraltar">Gibraltar</option>
<option value="Lifeline">Lifeline</option>
<option value="Mirage">Mirage</option>
<option value="Octane">Octane</option>
<option value="Pathfinder">Pathfinder</option>
<option value="Wraith">Wraith</option>
</select>
这是html代码。
答案 0 :(得分:0)
目录格式必须如下:
$target_dir = "Characters/Wraith/";
不是
$ target_dir =“ /字符/幽灵/”;