简体   繁体   English

从一个表单php上传多个文件

[英]Multiple files upload from one form php

I'm trying to upload two files from single form. 我正在尝试从单一表单上传两个文件。 However it's not getting uploaded to the folder location, I'm not able to find the error, too. 但是它没有上载到文件夹位置,我也找不到错误。

Here is my code: 这是我的代码:

HTML File HTML文件

<form action='/uploadfile.php' method='post' enctype='multipart/form-data'>
    <input type='file' name='photograph'>
    <input type='file' name='addressproof'>
    <input type='submit' class="button alt" value='SAVE'>
</form>

uploadfile.php uploadfile.php

    if($_FILES['photograph']['error']==0){
        $info = pathinfo($_FILES['photograph']['name']);
        $ext = $info['extension']; // get the extension of the file
        $newname = "photograph_".$userid.".".$ext; 

        if($ext=='jpg' || $ext=='png' || $ext=='jpeg' || $ext=='pdf'){
            $target = '/user_documents/photograph/'.$newname;
            move_uploaded_file( $_FILES['photograph']['tmp_name'], $target);
        }
    }

    if($_FILES['addressproof']['error']==0){
        $info = pathinfo($_FILES['addressproof']['name']);
        $ext = $info['extension']; // get the extension of the file
        $newname = "address_proof_".$userid.".".$ext; 

        if($ext=='jpg' || $ext=='png' || $ext=='jpeg' || $ext=='pdf'){
            $target = '/user_documents/address_proof/'.$newname;
            move_uploaded_file( $_FILES['addressproof']['tmp_name'], $target);
        }
    }

Can somebody help identify the error? 有人可以帮助您识别错误吗?

if($_FILES['addressproof']['error']==0){
    $info = pathinfo($_FILES['addressproof']['name']);
    $ext = $info['extension']; // get the extension of the file
    $newname = "address_proof_".$userid.".".$ext; 

    if($ext=='jpg' || $ext=='png' || $ext=='jpeg' || $ext=='pdf'){
        $target = 'user_documents/address_proof/'.$newname;  // remove the slash before user_documents/address_proof/
        move_uploaded_file( $_FILES['addressproof']['tmp_name'], $target);
    }
}

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

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