douwei1930 2015-09-07 02: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 02: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);
        }
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
编辑
预览

报告相同问题?

手机看
程序员都在用的中文IT技术交流社区

程序员都在用的中文IT技术交流社区

专业的中文 IT 技术社区,与千万技术人共成长

专业的中文 IT 技术社区,与千万技术人共成长

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

客服 返回
顶部