允许上传多种文件类型 [英] Allowing multiple file types to be uploaded

查看:192
本文介绍了允许上传多种文件类型的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个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 [" ]))&& (
_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(


这篇关于允许上传多种文件类型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆