php图片上传器

| 我有一个非常简单的照片上传器,需要加快速度 首先,即使页面中没有任何内容,页面加载时也会出现回声?
if($_POST[\'upload\']) {
     if($_FILES[\'image\'][\'name\'] == \"\")
     {
         #there\'s no file name return an error
         echo \"\\n<b>Please select a file to upload!\\n</b>\";
         exit;
     }
     #we have a filename, continue
}

#directory to upload to
$uploads = \'/home/habbonow/public_html/other/quacked/photos\';
$usruploads = \'photos\';

#allowed file types
$type_array = array(\'image/gif\',\'image/pjpeg\',\'image/x-png\');

if(!in_array($_FILES[\'image\'][\'type\'], $type_array))
{
    #the type of the file is not in the list we want to allow
    echo \"\\n<b>That file type is not allowed!\\n</b>\";
    exit;
}
页面输出显示上载框,但即使我没有单击该按钮,也回显\“不允许使用该文件类型!\”。 其次,请问jpg的mime类型是什么,因为我有jpeg和pjpeg。 谢谢,任何帮助表示赞赏。     
已邀请:
我还建议将所有内容都放入POST块中,否则无论页面如何加载都将对其进行评估。 对于mimetype,有一个image_type_to_mime_type方法,可让您传入表示给定文件类型的常量,并为其返回适当的mimetype,例如:
$type_array = array(image_type_to_mime_type(), image_type_to_mime_type(IMAGETYPE_GIF), image_type_to_mime_type(IMAGETYPE_PNG), \'image/pjpeg\');
(由于pjpeg没有它自己的常量,我们可以手动添加它)     
如果您尚未提交表单,我认为!inarray调用很可能返回false,因为$ _FILES [\'images \']不存在。 为此,我很想将全部放在第一条if语句中:
if($_POST[\'upload\']) {
     if($_FILES[\'image\'][\'name\'] == \"\")
     {
         #there\'s no file name return an error
         echo \"\\n<b>Please select a file to upload!\\n</b>\";
         exit;
     }
     #we have a filename, continue


     #directory to upload to
     $uploads = \'/home/habbonow/public_html/other/quacked/photos\';
     $usruploads = \'photos\';

     #allowed file types
     $type_array = array(\'image/gif\',\'image/pjpeg\',\'image/x-png\');

     if(!in_array($_FILES[\'image\'][\'type\'], $type_array))
     {
         #the type of the file is not in the list we want to allow
         echo \"\\n<b>That file type is not allowed!\\n</b>\";
         exit;
     }
}
    

要回复问题请先登录注册