如何使用PHP 5将任何类型的文件上传到服务器? [英] How to upload any type of file to the server using PHP 5?

查看:156
本文介绍了如何使用PHP 5将任何类型的文件上传到服务器?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想创建一个html表单,它可以将任何类型的文件(特定图像,pdf,doc和文本文件)上传到服务器。这是否可能使用单一功能。如果是,那么怎么做?

解决方案

=>试试这段代码上传任何类型的文件。 b

// HTML PAGE

 < li class =text>文件上传< /立GT; 
< li>< input type =filename =filevalue =class =input>< / li>

试试这个到所有文件上传..
// PHP PAGE

  if(isset($ _ POST ['submit'])!=){
$ name = $ _ FILES ['file' ]['名称'];
$ size = $ _ FILES ['file'] ['size'];
$ type = $ _ FILES ['file'] ['type'];
$ temp = $ _ FILES ['file'] ['tmp_name'];
$ caption1 = $ _ POST ['caption'];
$ link = $ _ POST ['link'];
move_uploaded_file($ temp,upload /\".$ name); //设置文件夹名称来存储所有文件。


I want to create a html form which can upload any type of file(to be specific image, pdf, doc and text files) to server. Is it possible using single function for this. If yes then how?

解决方案

=> Try this code for upload any type of file ..

//HTML PAGE

<li class="text">File Upload </li>
<li><input type="file" name="file" value="" class="input"  ></li>

try this to all file upload.. //PHP PAGE

if(isset($_POST['submit'])!=""){
  $name=$_FILES['file']['name'];
  $size=$_FILES['file']['size'];
  $type=$_FILES['file']['type'];
  $temp=$_FILES['file']['tmp_name'];
  $caption1=$_POST['caption'];
  $link=$_POST['link'];
  move_uploaded_file($temp,"upload/".$name);// set your folder name to store all file.

这篇关于如何使用PHP 5将任何类型的文件上传到服务器?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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