热卖商品
新闻详情
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 / \';
?
?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)
最新动态
2021-03-25
2021-03-25
2021-03-25
2021-03-25
2021-03-25
2017-07-29
2021-03-25
2021-03-25
2021-03-24
2021-03-25
2021-03-24
2021-03-25
联络我们