我有以下代码似乎适用于我的表单,但..... 脚本上传到名为temp的文件夹,而不是文件夹" image"。 如何告诉此脚本上传到所选文件夹?。
if($_POST){
//include database connection
include '../../libs/db_connect.php';
try{
if ($_FILES["file"]["error"] > 0)
echo "Error: " . $_FILES["image"]["error"] . "<br />";
else
{
echo "Upload: " . $_FILES["image"]["name"] . "<br />";
echo "Type: " . $_FILES["image"]["type"] . "<br />";
echo "Size: " . ($_FILES["image"]["size"] / 1024) . " Kb<br />";
echo "Stored in: " . $_FILES["image"]["tmp_name"];
}
答案 0 :(得分:1)
您需要使用move_uploaded_file
(link)函数将文件移动到特定目录。
默认情况下,PHP将上传的图像存储在临时目录中。
答案 1 :(得分:0)
我用这个:
$target_dir = 'your directory'
$target_file = $target_dir . basename($_FILES['uploadedFile']['name']);
/*enter conditions for check if upload is Ok here (file size, same names, etc), use $_FILES for comparations */
if ($uploadOK == true)
{ if (move_uploaded_file($_FILES['uploadedFile']['tmp_name'], $target_file))
{ echo 'Success!';
echo /*all you need to echo out, you can use $target_file for info about your file*/;
}
}