0

当用户上传图像时,有时图像会出现在配置文件文件夹中,有时不会。文件路径每次都会正确更新,因为我可以看到它在数据库中发生变化,但图像不会转到配置文件文件夹。谁能发现我做错了什么?

成员.php

if(isset($_FILES['profile']) === true) {
        if (empty($_FILES['profile'] ['name']) === true)  {
            echo 'Please choose a file!';
        }else{
            $allowed = array('jpg','jpeg','gif','png');

                $file_name = $_FILES['profile']['name'];
                $file_extn = explode('.', $file_name); 
                $file_extn = strtolower(end($file_extn));//converts string to lowercase
                $file_temp = $_FILES['profile']['tmp_name'];

                     if (in_array ($file_extn, $allowed) === true) {
                                //upload
                                change_image($MemberID,$file_temp,$file_extn);
                            }else {
                                echo 'Incorrect file type. Allowed: ';
                                echo implode(', ', $allowed);
                            }
                        }
                    }

用户.php

function change_image ($MemberID, $file_temp, $file_extn) {
    $file_path = 'images/profile/' . substr(md5(time()), 0, 10) . '.' . $file_extn; //take current time, create md5 hash, 10 character figure 
    move_uploaded_file($file_temp, $file_path);
    print_r ($file_path);
    mysql_query("UPDATE `member` SET `profile` = '" . mysql_real_escape_string($file_path) . "' WHERE MemberID = " . $MemberID) ;//update database

}
4

0 回答 0