简体   繁体   English

上传图片并将其存储在两个不同的目录中

[英]Upload an image and store it in two different directories

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: 这是我的HTML代码:

<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: 这是我的PHP代码:

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? 谁能告诉我如何上传图片并将其保存在其他文件夹中?

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 对于第二个文件,保存到目录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. 请注意,文件上传需要enctype="multipart/form-data"

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM