文件上传仅适用于某些图像(class.upload.php)

问题描述:

我尝试了使用PHP上传图像的本机方法,但是我的朋友向我建议使用class.upload.php库,该库的结果仍然与以前相同.我只能上传某些图像而没有它们的小图标,这意味着浏览器无法找到该图像,但是奇怪的是,当我将无效"图像下载到计算机上时,它们就可以了.大约有50%的图像实际上可以工作,但其余图像仅显示应具有的适当大小,但没有图像.这是我的代码(我的html表单具有名为filename的文件输入类型:

I've tried the native way of uploading images with PHP, but my friend suggested me to the class.upload.php library, which still had the same results as before. I can only upload certain images without them having that little icon that means that the browser can't find the image, but what's weird is that when I download the "invalid" images to my computer, they're fine. About 50% of images actually do work, but the rest just show the appropriate size that they should have but no image. Here is my code (my html form has a file input type called filename:

$handle = new upload($_FILES['filename']);

if ($handle->uploaded)   
{
   if ($file_src_size < 20000)
   {
        $handle->file_new_name_body = "test";  
        $handle->image_convert = 'jpg';
        $handle->process('/');  

        echo "<img src = \"test.jpg\" />";
    }
    else echo "Files must be 20 kb or under";
}
else echo "Upload failed, please try again";

可以下载图像并在本地重新显示的事实表明,问题不在于上传脚本.另一个问题可能是图像没有正确保存以供Web查看.例如,仅因为文件以.jpg结尾并且可以在本地查看并不意味着该文件可被浏览器识别.许多浏览器无法查看CMYK jpeg.

The fact that you can download the images and re-display locally them suggests that the problem is not with the upload script. An alternative problem could be that the images are not properly saved for web viewing. For example, just because a file ends in .jpg and can be viewed locally does not mean that it is recognizable by a browser. A CMYK jpeg cannot be viewed by many browsers.