脚本适用于计算机而非服务器?

Cor*_*ory 0 php

奇怪的问题......我不知道为什么这不能在我的服务器上运行.

出于某种原因,IF不起作用.

令我困惑的主要问题是检查文件扩展名的那个.即使由于某种原因它在我的服务器而不是我的电脑上返回TRUE也不匹配.

    if (isset($_POST['submit'])) {

    $sizelimit = 50; //File size limit in KB.
    $destination_folder = 'images/user_avatars/temp/';

    $fileurl = $_POST['avatar_url'];
    $filetype = substr(strrchr($fileurl,'.'),1);
    $filename = "user_" . $_SESSION[user_id] . "." . $filetype;

    $temp = $destination_folder . $filename;

    if ($filetype == "gif" || "png" || "jpg" || "jpeg") {

        $file = fopen ($url, "rb");
        if ($file) {
            $newfile = fopen ($temp, "wb");
            if ($newfile) {
                while(!feof($file)) {
                    fwrite($newfile, fread($file, 1024 * 8 ), 1024 * 8 );
                }
            }
        }

        if ( filesize($temp) > 1024 * $sizelimit ) {
            $errors .= "The file size of the image you entered is too large!";
        }
    } else {
        $errors .= "The URL you entered is not a valid image!";
    }

    if (isset($errors)) {
        $smarty->assign("error_message", $errors);
        unlink($temp);
    } else {
        $avatar_sql = "
            UPDATE
                users
            SET
                user_avatar = '$filename'
            WHERE
                user_id = '$_SESSION[user_id]'
        ";
        $avatar_query = @mysqli_query ($db_connect, $avatar_sql);

        fclose($file);
        fclose($newfile);
    }
}
Run Code Online (Sandbox Code Playgroud)

pes*_*taa 6

if ($filetype == "gif" || "png" || "jpg" || "jpeg")
Run Code Online (Sandbox Code Playgroud)

这就是您的脚本不可靠的原因.请改用:

if ($filetype == "gif" || $filetype == "png" || $filetype == "jpg" || $filetype == "jpeg" )
Run Code Online (Sandbox Code Playgroud)

甚至更好:

if (in_array($filetype, array("gif", "png", "jpg", "jpeg))
Run Code Online (Sandbox Code Playgroud)

没有一个翻译能够聪明地思考而不是你.你需要准确地告诉它你的意思.