我是来问的(因为我今天搜索了很多互联网)
情况如下:得到一个包含一些字段的表单,然后它有 2 个输入 type="file"。关键是我希望文件 A 转到文件夹 A,而文件 B 转到文件夹 B。
我尝试了什么:
这是 projs_upload.php
$uploaddirb = '../images/projects/';
$uploaddira = '../images/projects/thumb/';
$uploadfile = $uploaddira . basename($_FILES['min_img']['name']);
$uploadimg = $uploaddirb . basename($_FILES['img']['name']);
move_uploaded_file($_FILES['min_img']['tmp_name'], $uploadfile);
move_uploaded_file($_FILES['img']['tmp_name'], $uploadimg);
这是形式:
require("common.php");
if($_POST){
$query = "
INSERT INTO projects (
`idprojects`,
`cat`,
`name`,
`desc`,
`min_img`,
`img`,
`ext_url`
) VALUES (
:idprojects,
:cat,
:name,
:desc,
:min_img,
:img,
:ext_url
)
";
$query_params = array(
':idprojects'=> "",
':cat' => $_POST['cat'],
':name' => $_POST['name'],
':desc' => $_POST['desc'],
':min_img' => $_FILES['min_img']['name'],
':img' => $_FILES['img']['name'],
':ext_url' => $_POST['exturl']
);
try
{
$stmt = $db->prepare($query);
$result = $stmt->execute($query_params);
}
catch(PDOException $ex)
{
die("Failed to run query: " . $ex->getMessage());
}
include ("funcs/proj_uploads.php");
header("Location: ?p=manage_projects");
die("Redirecting done");
}
<form action="?p=manage_projects" method="post" enctype="multipart/form-data">
<input type="text" placeholder="kategoria" name="cat" />
<input type="text" placeholder="nazwa projektu" name="name" />
<input type="text" placeholder="link do projektu" name="exturl" />
<textarea placeholder="opis" name="desc" />
</textarea>
<input type="hidden" name="MAX_FILE_SIZE" value="512000" />
<input type="file" placeholder="miniatura" name="img" />
<input type="file" placeholder="duży" name="img" />
<button type="submit" class="expand">Zapisz</button>
</form>
而“?p=manage_projects”指的是表单页面。