无法在PHP中上传文件

时间:2016-11-16 09:48:19

标签: php

我尝试在php上传文件,但我无法这样做。我收到成功消息,我的记录也保存在数据库中,但我的文件夹不包含该上传的文件。 images文件夹是空的。

请帮忙。

我的HTML代码:

if($_FILES['site_logo']['name'] != ''){
            $uploaded_file = $_FILES['site_logo']['name'];
            $exp = explode(".",$uploaded_file);
            $extension = end($exp);
            $allowed_types = array('jpg',"jpeg","png","gif");
            if(in_array($extension,$allowed_types)){

                $path = "images/".$uploaded_file;

                if(move_uploaded_file($_FILES['site_logo']['tmp_name'],$path))
                {
                    $_SESSION['upload_success'] = "File Uploaded succesfully"; 
                }
                else
                {
                    $_SESSION['upload_error'] = "Something went wrong, file cannot be uploaded"; 
                }
            }   
            else
            {
                $_SESSION['upload_warning'] = "Please upload appropriate file type"; 
            }
        }   
        else
        {
            $_SESSION['upload_warning'] = "Please upload file"; 
        }

2 个答案:

答案 0 :(得分:0)

我认为您的 $ path 不正确

你能改变吗

  

$ path =“./ image /".$ uploaded_file;

如果不能正常显示您的文件夹结构

答案 1 :(得分:0)

你应该使用

move_uploaded_file($_FILES["site_logo"]['tmp_name'],$path) 

而不是

move_uploaded_file($_FILES['site_logo']['tmp_name'],$path).
相关问题