PHP上传的图像被截断

时间:2013-02-18 14:26:03

标签: php image file-upload

我有一个上传图片的表单< 500KB 我遇到的问题是服务器上传的图像部分可见/缺少部分图像。

有谁知道这可能是什么问题?

if(isset($_POST['Submit']))
{
    $image = $_FILES['image']['name'];  //reads the name of the file the user submitted for uploading
    if ($image) //if it is not empty
    {   
        $filename = stripslashes($_FILES['image']['name']); //get the original name of the file from the clients machine
        $extension = getExtension($filename);//get the extension of the file in a lower case format
        $extension = strtolower($extension);

        if (($extension != "jpg") && ($extension != "jpeg") && ($extension != "png") && ($extension != "gif")){
            echo '<h1>Error, allowed only: .jpg, .png, .gif</h1>';
            $errors=1;
        }else{
            $size = filesize($_FILES['image']['tmp_name']);

            if ($size > 512000){
                echo '<h1 style="color:red;">Too big (Max: 500KB). Try again. </h1>';
                $errors=1;
            }else{ //MAX SIZE IS SMALLER

                $s = $_POST['first_name'];
                $ts = array("/ä/","/Ä/");
                $tn = array("a","A");



                $image_name= preg_replace($ts,$tn, str_replace(' ','+',$s)).'_'.time().'.'.$extension; // $image_name=time().'.'.$extension;
                $newname="img/uploads/images/".$image_name;

                $copied = copy($_FILES['image']['tmp_name'], $newname);
                if (!$copied)
                {
                    echo '<h1>Could not upload image</h1>';
                    $errors=1;
                }

            }
        }
    }
}

enter image description here

^^^^更多的图像缺失

1 个答案:

答案 0 :(得分:3)

您上传的图片已被截断,因此假设该文件未完成上传是公平的。也许服务器上的临时目录已满,也许你的服务器上的配额已经过了。我在我的服务器上测试了你的代码,这里没有问题。