Heim php教程 PHP源码 PHP 文件上传

PHP 文件上传

May 25, 2016 pm 05:14 PM
PHP-Datei hochladen

php代码

<html>
<head>
<title>图片上传</title>
</head>
<body>
<form enctype="multipart/form-data" method="post" name="upform">
上传文件:<input type="file" name="upfile" value="">
<input type="submit" value="上传"><br>
<?php
//能够上传的类型
$uptypes=array(&#39;image/jpg&#39;,&#39;image/jpeg&#39;,&#39;image/png&#39;,&#39;image/pjpeg&#39;,&#39;image/gif&#39;,
&#39;image/bmp&#39;,&#39;image/x-png&#39;);
?>
允许上传的文件类型为:<?=implode(&#39;,&#39;,$uptypes)?>
</form>
</body>
</html>
<?php
$max_file_szie=2*pow(2,20);  //上传的文件小于2MB
$destination_folder=&#39;uploadimg/&#39;; //上传文件保存路径
if($_SERVER[&#39;REQUEST_METHOD&#39;]==&#39;POST&#39;){  
		if(!is_uploaded_file($_FILES[&#39;upfile&#39;][&#39;tmp_name&#39;])){
				echo &#39;图片不存在!&#39;;
				exit;
			}
		if($max_file_szie<$_FILES[&#39;upfile&#39;][&#39;size&#39;]){
				echo &#39;文件太大了!&#39;;
				exit;
			}
		if(!in_array($_FILES[&#39;upfile&#39;][&#39;type&#39;],$uptypes)){
				echo &#39;文件类型不符合!&#39;.$_FILES[&#39;upfile&#39;][&#39;type&#39;];
				exit;
			}
		if(!file_exists($destination_folder)){
				mkdir($destination_folder);
            }
		$filename=$_FILES[&#39;upfile&#39;][&#39;tmp_name&#39;];
		$image_size=getimagesize($filename);
		$pinfo=pathinfo($_FILES[&#39;upfile&#39;][&#39;name&#39;]); //文件路径信息
		$ftype=$pinfo[&#39;extension&#39;]; //旧文件后缀名
		$destination = $destination_folder.time().".".$ftype; //新文件名称
		if(file_exists($destination)&&$voerwrie !=true){
				echo &#39;同名文件已经存在了!&#39;;
				exit;
			}
		//把上传的文件从临时文件夹移动到指定目录
		if(!move_uploaded_file($filename,$destination)){ 
				echo &#39;移动文件出错了!&#39;;
				exit;
			}
		$pinfo=pathinfo($destination);
		$fname=$pinfo[basename];
		echo "<font color=&#39;red&#39;>已经成功上传</font><br>文件名:
              <font color=&#39;blue&#39;>".$destination_folder.$fname."</font><br>";
		echo &#39;宽度:&#39;.$image_size[0];
		echo &#39;高度:&#39;.$image_size[1];
		echo &#39;<br>大小:&#39;.$_FILES[&#39;upfile&#39;][&#39;size&#39;]."bytes";
	}
?>
Nach dem Login kopieren
Erklärung dieser Website
Der Inhalt dieses Artikels wird freiwillig von Internetnutzern beigesteuert und das Urheberrecht liegt beim ursprünglichen Autor. Diese Website übernimmt keine entsprechende rechtliche Verantwortung. Wenn Sie Inhalte finden, bei denen der Verdacht eines Plagiats oder einer Rechtsverletzung besteht, wenden Sie sich bitte an admin@php.cn

Heiße KI -Werkzeuge

Undresser.AI Undress

Undresser.AI Undress

KI-gestützte App zum Erstellen realistischer Aktfotos

AI Clothes Remover

AI Clothes Remover

Online-KI-Tool zum Entfernen von Kleidung aus Fotos.

Undress AI Tool

Undress AI Tool

Ausziehbilder kostenlos

Clothoff.io

Clothoff.io

KI-Kleiderentferner

AI Hentai Generator

AI Hentai Generator

Erstellen Sie kostenlos Ai Hentai.

Heißer Artikel

R.E.P.O. Energiekristalle erklärten und was sie tun (gelber Kristall)
3 Wochen vor By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Beste grafische Einstellungen
3 Wochen vor By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. So reparieren Sie Audio, wenn Sie niemanden hören können
3 Wochen vor By 尊渡假赌尊渡假赌尊渡假赌
WWE 2K25: Wie man alles in Myrise freischaltet
3 Wochen vor By 尊渡假赌尊渡假赌尊渡假赌

Heiße Werkzeuge

Notepad++7.3.1

Notepad++7.3.1

Einfach zu bedienender und kostenloser Code-Editor

SublimeText3 chinesische Version

SublimeText3 chinesische Version

Chinesische Version, sehr einfach zu bedienen

Senden Sie Studio 13.0.1

Senden Sie Studio 13.0.1

Leistungsstarke integrierte PHP-Entwicklungsumgebung

Dreamweaver CS6

Dreamweaver CS6

Visuelle Webentwicklungstools

SublimeText3 Mac-Version

SublimeText3 Mac-Version

Codebearbeitungssoftware auf Gottesniveau (SublimeText3)