本文介绍了允许上传多种文件类型的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个php脚本,可以将文件上传到服务器.目前仅允许使用jpg图片.如何允许上传更多文件类型,例如mp3,WAV和GIF? 代码如下:
I have a php script that uploads a file to the server. Currently only jpg images are allowed. How can I allow more file types to be uploaded such as mp3''s, WAV, and GIF? Code Below:
<?php //Сheck that we have a file if((!empty($_FILES["uploaded_file"])) && ($_FILES['uploaded_file']['error'] == 0)) { //Check if the file is JPEG image and it's size is less than 350Kb $filename = basename($_FILES['uploaded_file']['name']); $ext = substr($filename, strrpos($filename, '.') + 1); if (($ext == "jpg") && ($_FILES["uploaded_file"]["type"] == "image/jpeg") && ($_FILES["uploaded_file"]["size"] < 35000000)) { //Determine the path to which we want to save this file $newname = dirname(__FILE__).'/files/'.$filename; //Check if the file with the same name is already exists on the server if (!file_exists($newname)) { //Attempt to move the uploaded file to it's new place if ((move_uploaded_file($_FILES['uploaded_file']['tmp_name'],$newname))) { echo "It's done! The file has been saved as: ".$newname;非常感谢您的帮助..预先感谢.
Any help is greatly appreciated.. Thanks in advance.
推荐答案_FILES [" uploaded_file" ]))&& ( _FILES["uploaded_file"])) && (
_FILES [' uploaded_file'] [' 错误'] == 0)){ // 检查文件是否为JPEG图像且文件大小小于350Kb _FILES['uploaded_file']['error'] == 0)) { //Check if the file is JPEG image and it's size is less than 350Kb
文件名 = basename( filename = basename(
更多推荐
允许上传多种文件类型
发布评论