繁体   English   中英

Php图像类型上传问题gif png

[英]Php image type upload problems gif png

我有这部分代码,我尝试了一些像“或”和“其他”的东西,但它对我来说不正常。 因此,它适用于.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.ini文件中的设置:

upload_max_filesize
post_max_size

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM