note 76561 added to function.system
| From: | timgolding_10 at hotmail dot com | Date: | Fri, 20 Jul 2007 14:19:10 +0000 |
| Subject: | note 76561 added to function.system | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-128764@lists.php.net to get a copy of this message | ||
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 />';
?>
----
Server IP: 194.145.210.3
Probable Submitter: 82.70.255.62
----
Manual Page -- http://www.php.net/manual/en/function.system.php
Edit -- https://master.php.net/note/edit/76561
Del: integrated -- https://master.php.net/note/delete/76561/integrated
Del: useless -- https://master.php.net/note/delete/76561/useless
Del: bad code -- https://master.php.net/note/delete/76561/bad+code
Del: spam -- https://master.php.net/note/delete/76561/spam
Del: non-english -- https://master.php.net/note/delete/76561/non-english
Del: in docs -- https://master.php.net/note/delete/76561/in+docs
Del: other reasons-- https://master.php.net/note/delete/76561
Reject -- https://master.php.net/note/reject/76561
Search -- https://master.php.net/manage/user-notes.php