機能のmysql
家族が廃止され、あなたはどちらかmysqli
かPDO
にあなたのコードをアップグレードして、悪質なSQLインジェクションを防ぐためにprepared statements
を活用する必要がありますので、完全に7+ PHPから削除されました。私はまた、ユーザーがファイルをアップロードすることを許可しているので、アップロードされたファイルのより多くの処理を実行して、予想されるタイプであることを確認する必要があります。
<!doctype html>
<html>
<head>
<title>Video upload</title>
</head>
<body>
<?php
function getmimetypes(){
$url='http://svn.apache.org/repos/asf/httpd/httpd/trunk/docs/conf/mime.types';
$types=array();
array_walk(file($url), function($line, $key, $types){
if($line && !empty($line) && strpos($line, chr(35))===false){
list($m, $e)=array_values(array_filter(preg_split('@\[email protected]', trim($line))));
if(strpos($e, chr(32))){
$o=explode(chr(32), $e);
foreach($o as $e) $types[ $e ]=$m;
} else {
$types[ $e ]=$m;
}
}
}, &$types);
return $types;
}
if($_SERVER['REQUEST_METHOD']=='POST' && isset($_FILES['uploadvideo'], $_POST['upload'])){
/* permitted extensions */
$exts=array('mp4', 'mov', 'avi');
/* permitted mimetypes */
$mimetypes=array('video/mp4', 'video/quicktime', 'video/x-msvideo');
/* Get an array of possible Mimetypes */
$types = getmimetypes();
/* For simplicity, cast as an object */
$obj=(object)$_FILES['uploadvideo'];
$name=$obj->name;
$tmp=$obj->tmp_name;
$size=$obj->size;
$type=$obj->type;
$error=$obj->error;
$cname=str_replace(" ", "_", $name);
/* get file extension */
$ext = pathinfo($name, PATHINFO_EXTENSION);
/* set the target path */
$target="test_upload/{$cname}";
/* process the uploaded file */
if(is_uploaded_file($tmp) && $error == UPLOAD_ERR_OK){
/*
additional checks on file - is it of the correct extension and mimetype?
*/
if(in_array($ext, $exts) && in_array($type, $mimetypes)){
$result = @move_uploaded_file($tmp, $target);
$sql='insert into `video` (`name`,`type`) values ("'.$cname.'","'.$type.'");';
if($result){
$result = mysql_query($sql);
echo $result ? 'Your video '.$cname.' has been successfully uploaded and saved' : 'There was a problem saving your video';
} else {
echo 'Unable to move your video to it\'s new location';
}
}
} else {
echo 'Error: Possible attack';
}
}
?>
<form enctype='multipart/form-data' method='post'>
<input name='MAX_FILE_SIZE' value='100000000000000' type='hidden' />
<input type='file' name='uploadvideo' />
<input type='submit' name='upload' value='Upload' />
</form>
</body>
</html>