4000-520-616
欢迎来到免疫在线!(蚂蚁淘生物旗下平台)  请登录 |  免费注册 |  询价篮
主营:原厂直采,平行进口,授权代理(蚂蚁淘为您服务)
咨询热线电话
4000-520-616
当前位置: 首页 > 新闻动态 >
新闻详情
PHP: system - Manual
来自 : www.php.net/manual/zh/functi.. 发布时间:2021-03-25
An example of using the system to call the file command on a linux server. This script detects whether a user posted file is a jpeg, gif or png

?PHP

$accepted_types=array(\"JPEG\" , \"GIF\", \"PNG\");

// The temporary filename of the file in which the uploaded file was stored on the server.
if(!empty($_FILES[\"uploadedfile\"]))
{
$uploaddir = $_SERVER[\'DOCUMENT_ROOT\'].\"/images/\";
$uploaddir.=basename( $_FILES[\'uploadedfile\'][\'name\']);

//verfiy file using linux FILE command
$last_line = system(\'file \'.escapeshellarg($_FILES[\'uploadedfile\'][\'tmp_name\']), $retval);

//get the file extension returned through magic database
$splitvals=explode(\' image data\' , $last_line);
$vals=explode(\':\', $splitvals[0]);
$vals[1]=str_replace(\' \',\'\', $vals[1]);

if (in_array($vals[1], $accepted_types))
{
echo $vals[1].\' was accepted br / \';
if(!file_exists($uploaddir)){
//Copy the file to some permanent location
if(move_uploaded_file($_FILES[\"uploadedfile\"][\"tmp_name\"], $uploaddir))
{
echo $uploaddir.\" was uploaded! br / \";
}
else
{
echo \"There was a problem when uploding the new file, please contact admin about this.\";
}
}
else echo \'This file already exists in DB please rename file before uploading\';
}
}else echo $_FILES[\'uploadedfile\'][\'error\'].\' br / \';
?

本文链接: http://syskem.immuno-online.com/view-764890.html

发布于 : 2021-03-25 阅读(0)