PHP - 我无法保存任何文件

时间:2015-02-18 00:08:13

标签: php upload

解决我的问题有点困难..好吧,我正在创建一个上传文件,用户可以只保存文件.txt,.pdf或.doc,但有一些文件作为返回数组($ _FILES)为空的照片和另一张大小等于上一张照片的照片,返回两条错误信息的方式正确..

拜托,我的逻辑错了吗?

 <?php 


    if(isset($_FILES['file']['name'])){

        $valid_file = true; 
        //Errors Messages
        $messageError = array(); 

        //Types
        $allowTypes = array('text/plain','application/msword','application/pdf');   

        $folder = 'C:\wamp\www\uploadtest\files/';
        $path = $folder.basename($_FILES['file']['name']);

        if(!$_FILES['file']['error'])
        {
            //Check Types
            if(!in_array($_FILES['file']['type'], $allowTypes)){
                $valid_file = false;
                $messageError[] = 'File type not allowed';
            }

            //Check Size            
            if($_FILES['file']['size'] > (1024000))
            {
                $valid_file = false;
                $messageError[] = "Oops!  can't be larger than 1 MB";           
            }       

            //Upload Process        
            if($valid_file){            
                if(move_uploaded_file($_FILES['file']['tmp_name'],$path)){
                    echo "Sent!";
                }else{
                    echo "Error to send!";
                }       
            }
        }else{      
            echo 'Ooops! '.$_FILES['file']['error'];
        }

    }else{
        $messageError[] = "Please, Select a File!"; 
    }

        if(isset($messageError) or !empty($messageError)){
            foreach ($messageError as $me) {
                echo $me.'<br>';
            }
        }
    ?>

0 个答案:

没有答案