douwei1930 2015-09-07 10:44
浏览 64
已采纳

从一个表单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

<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

    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?

  • 写回答

1条回答 默认 最新

  • duandong2562 2015-09-07 10:57
    关注
    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);
        }
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?