【发布时间】: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))) {
【问题讨论】: