我有一个非常简单的照片上传器,需要一些提速。
首先,当页面加载时会出现回声,甚至在框中什么都没有?
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。
谢谢,任何帮助都感谢。
发布于 2011-04-16 11:38:04
我还建议将所有内容都放在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没有它自己的常量,所以我们可以手动添加它)
发布于 2011-04-16 11:32:06
如果您还没有提交表单,我认为,因为$_FILES‘映像’将不存在,所以!内联调用很可能返回false。
为此,我很想把整件事放在第一个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;
}
}https://stackoverflow.com/questions/5686119
复制相似问题