I'm here to ask (cause I've searched today tons of internet for this)
Here's the case: got one form with some fields, and then it have 2 inputs type="file". The point is that I want the file A go to folder A, and the file B go to folder B.
what I tried:
this is 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);
this is form:
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>
and "?p=manage_projects" refers to the form page.