It is required that the file to be uploaded must be an image. if it is another file, it cannot be uploaded. how can this problem be solved? {Code...} specifies that the file to be uploaded can only be an image. if it is another file, it cannot be uploaded. how can this problem be solved?
if($_SERVER['REQUEST_METHOD']=='POST'){ if(is_uploaded_file($_FILES['up']['tmp_name'])){ $path='./upload/'; is_dir($path) || mkdir($path,0777,true); $type=ltrim(strchr($_FILES['up']['type'],'/'),'/'); $fileName = time().mt_rand(0, 9999).'.'.$type; $fullpath = $path . $fileName; move_uploaded_file($_FILES['up']['tmp_name'], $fullpath); }}
Reply content:
It is required that the file to be uploaded must be an image. if it is another file, it cannot be uploaded. how can this problem be solved?
if($_SERVER['REQUEST_METHOD']=='POST'){ if(is_uploaded_file($_FILES['up']['tmp_name'])){ $path='./upload/'; is_dir($path) || mkdir($path,0777,true); $type=ltrim(strchr($_FILES['up']['type'],'/'),'/'); $fileName = time().mt_rand(0, 9999).'.'.$type; $fullpath = $path . $fileName; move_uploaded_file($_FILES['up']['tmp_name'], $fullpath); }}
There is a risk of judging by the extension
Determine by MIME Types