【问题标题】:Php image type upload problems gif pngphp图片类型上传问题gif png
【发布时间】:2014-05-10 14:55:37
【问题描述】:

我有这部分代码,我尝试了一些类似“or”和“else”的东西,但它对我来说不能正常工作。所以 atm 它适用于 .jpg 文件格式,并且可以很好地上传,当我尝试添加 .gif 限制为 1-2mb 时它没有上传它。你能帮忙吗?

if (($ext == "jpg") && ($_FILES["uploaded_file"]["type"] == "image/jpeg") && ($_FILES["uploaded_file"]["size"] < 350000))

我用过

if (($ext == "gif") && ($_FILES["uploaded_file"]["type"] == "image/gif") && ($_FILES["uploaded_file"]["size"] < 2000000))

用于 gif 和

if (($ext == "png") && ($_FILES["uploaded_file"]["type"] == "image/png") && ($_FILES["uploaded_file"]["size"] < 1000000))

但它没有用,所以如果有人可以帮助我,请=)

仅 jpeg 的完整部分代码是:

if((!empty($_FILES["uploaded_file"])) && ($_FILES['uploaded_file']['error'] == 0)) {
                  //Check if the file is JPEG image and it's size is less than 350Kb
                  $filename = basename($_FILES['uploaded_file']['name']);
                  $ext = substr($filename, strrpos($filename, '.') + 1);
                  if (($ext == "jpg") && ($_FILES["uploaded_file"]["type"] == "image/jpeg") && ($_FILES["uploaded_file"]["size"] < 350000)){
                    //Determine the path to which we want to save this file
                      $newname = dirname(__FILE__).'/upimg/'.$filename;
                      //Check if the file with the same name is already exists on the server
                      if (!file_exists($newname)) {
                        //Attempt to move the uploaded file to it's new place
                        if ((move_uploaded_file($_FILES['uploaded_file']['tmp_name'],$newname))) {

【问题讨论】:

    标签: php png jpeg gif


    【解决方案1】:

    检查php.ini文件中的设置:

    upload_max_filesize
    post_max_size
    

    如果最大尺寸太小,则不会上传文件。增加尺寸,看看它是否能解决您的问题。

    【讨论】:

    • 谢谢,我完全忘记了!
    • @Sandra 我的荣幸 :)
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-01-13
    • 1970-01-01
    • 2017-06-30
    • 2011-06-04
    相关资源
    最近更新 更多