允许上传多种文件类型

编程入门 行业动态 更新时间:2024-10-21 16:08:26
本文介绍了允许上传多种文件类型的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我有一个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(

更多推荐

允许上传多种文件类型

本文发布于:2023-07-17 03:32:27,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1128990.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:文件类型   多种   上传

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!