-1

当我上传 jpg 文件时,我的代码正在回显 else 语句。我错过了什么我哪里出错了吗?

顺便说一句,它在代码的第 39 行

if(($type=="image/jpeg") || ($type=="image/JPG") || ($type=="image/bmp") || ($type=="image/png")) 
{
    move_uploaded_file($temp, "images/$mypic");
    echo "What a pretty face! <img border='1' width='50' height='50' src='images/$mypic'><p>";
    mysqli_query($link,$query);

    echo ("user registered successfully!<a href='home.php'>Login now!</a>");
}
else
{
    echo ($type);
    echo "Please load a valid jpeg, jpg or bmp! And size must be less than 10k!";           }
} 
4

3 回答 3

0

尝试这样做:

$type_arr = array(
  "image/jpeg", "image/jpg", "image/bmp", "image/png"
);
//and
$type = strtolower($type);
if( in_array($type, $type_arr) ) {
    //your upload code here
}
else {
   //error message
   echo $type;
}
于 2013-09-12T09:37:02.643 回答
0

我想你正在检查图像,我会这样做

if(!(getimagesize ($temp)==0))
{
//an image
}
else
{
//not an image
}
于 2013-09-12T10:15:26.093 回答
0

我认为这是您的文件大小问题。检查一次。

$allow = array("jpg", "jpeg", "gif", "png");

$todir = 'uploads/';

if ( !!$_FILES['file']['tmp_name'] ) // is the file uploaded yet?
{
$ext = explode('.', strtolower( $_FILES['file']['name']) ); // whats the extension of the file

if ( in_array( $ext, $allow) ) // is this file allowed
{
    if ( move_uploaded_file( $_FILES['file']['tmp_name'], $todir . basename($_FILES['file']['name'] ) ) )
    {
        // the file has been moved correctly
    }
}
else
{
    // error this file ext is not allowed
}
}
于 2013-09-12T09:40:09.040 回答