Php图像类型上传问题gif png

时间:2014-03-31 09:59:40

标签: php png jpeg gif

我有这部分代码,我尝试了很少的东西,如"或"和"否则"但它对我来说没有用。因此它适用于.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))) {

1 个答案:

答案 0 :(得分:2)

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

upload_max_filesize
post_max_size

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