我必须按照以下代码使用 php 上传文件:
<!DOCTYPE html>
<html>
<head>
<title>Upload your files</title>
</head>
<body>
<form enctype="multipart/form-data" action="upload.php" method="POST">
<p>Upload your file</p>
<input type="file" name="uploaded_file"></input><br />
<input type="submit" value="Upload"></input>
</form>
</body>
</html>
<?PHP
if(!empty($_FILES['uploaded_file']))
{
$path = "uploads/";
$path = $path . basename( $_FILES['uploaded_file']['name']);
if(move_uploaded_file($_FILES['uploaded_file']['tmp_name'], $path)) {
echo "The file ". basename( $_FILES['uploaded_file']['name']).
" has been uploaded";
} else{
echo "There was an error uploading the file, please try again!";
}
}
?>
它的工作原理,但很好,我的问题是如何添加/实现基于文件类型的安全验证并转换文件?
所有图像文件应转换为jpg 类型,所有视频文件应转换为mp4 类型。
在上传过程中,我还应该randon()为文件添加名称。
重要提示:验证后,所有图像都应转到upload/images/,所有视频都应转到upload/videos/
慕娘9325324
HUWWW