php照片上传器

php照片上传器,php,photo,uploader,Php,Photo,Uploader,我有一个非常简单的照片上传需要一些提高速度请 首先,页面加载时会出现回音,即使框中没有任何内容 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

我有一个非常简单的照片上传需要一些提高速度请

首先,页面加载时会出现回音,即使框中没有任何内容

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;
}
if($\u POST['upload'])){
如果($\u文件['image']['name']==“”)
{
#没有文件名返回错误
echo“\n请选择要上载的文件!\n”;
出口
}
#我们有一个文件名,是否继续
}
#要上载到的目录
$uploads='/home/habbonow/public_html/other/quacked/photos';
$usruploads=‘照片’;
#允许的文件类型
$type_array=array('image/gif'、'image/pjpeg'、'image/x-png');
if(!in_数组($_文件['image']['type'],$type_数组))
{
#文件类型不在我们要允许的列表中
echo“\n不允许使用该文件类型!\n”;
出口
}
页面输出显示上传框,但也会回显“该文件类型不允许!”即使我没有单击按钮

其次,请告诉我jpg的mime类型是什么,因为我有jpeg和pjpeg

谢谢,谢谢你的帮助



如果您尚未提交表格,我认为!inarray调用很可能返回false,因为$\u文件['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;
     }
}
if($\u POST['upload'])){
如果($\u文件['image']['name']==“”)
{
#没有文件名返回错误
echo“\n请选择要上载的文件!\n”;
出口
}
#我们有一个文件名,是否继续
#要上载到的目录
$uploads='/home/habbonow/public_html/other/quacked/photos';
$usruploads=‘照片’;
#允许的文件类型
$type_array=array('image/gif'、'image/pjpeg'、'image/x-png');
if(!in_数组($_文件['image']['type'],$type_数组))
{
#文件类型不在我们要允许的列表中
echo“\n不允许使用该文件类型!\n”;
出口
}
}

我还建议将所有内容都放在POST块中,否则无论发生什么情况,都会在加载页面时对其进行评估

对于mimetype,有一种方法可以让您传入表示给定文件类型的常量,并为其返回正确的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没有自己的常数,我们可以手动添加)

将其全部放在单个if{}中,现在不会出错,谢谢:)很高兴我能提供帮助。