Reputation: 59
Hi, I have a form which has two file uploaders. I want to have the second file uploader upload an image and store it in two different folders.
Can anyone help me out? Here is my HTML code:
<input type="file" name="file" id="file"><br>
<input type="submit" name="upload" value="Upload Image">
<input type="file" name="thumb" id="thumb"><br>
<input type="submit" name="updthumb" value="Upload Thumb impression">
Here is my PHP code:
if(isset($_POST["upload"])){
$image ="upload/";
move_uploaded_file($_FILES["file"]["tmp_name"], $image . $_FILES["file"]["name"]);
$newfilepath2 = $image . $_FILES["file"]["name"];
mysql_query("UPDATE `candidate` SET `imgpath`='$newfilepath2' WHERE vouchno='$vouch'") or die(mysql_error());
header("refresh: 1; candproc.php?vouchno=$vouch");
}
Can anyone help in telling me how to upload the image and save it in a different folder?
Upvotes: 0
Views: 1651
Reputation: 7501
Something like:
$thumbspath ="thumbs/";
$thumb = $thumbspath . $_FILES["thumb"]["name"];
move_uploaded_file($_FILES["thumb"]["tmp_name"], $thumb);
For the second file, saving into the directory thumbs
You should have set your form:
<form action="phpscript.php" method="post" enctype="multipart/form-data">
<input type="file" name="file" id="file"><br>
<input type="file" name="thumb" id="thumb"><br>
<input type="submit" name="upload" value="Upload files">
</form>
Note that enctype="multipart/form-data"
is required for file uploads.
Upvotes: 1