首页 >php教程 >PHP源码 >PHP 文件上传脚本

PHP 文件上传脚本

PHP中文网
PHP中文网原创
2016-05-25 17:16:081002浏览

1.fileupload.php

<html>
 <head>
 <title>A File Upload Script</title>
 </head>
 <body>
 <div>
 <?php
 if ( isset( $_FILES[&#39;fupload&#39;] ) ) {
 
     print "name: ".     $_FILES[&#39;fupload&#39;][&#39;name&#39;]       ."<br />";
     print "size: ".     $_FILES[&#39;fupload&#39;][&#39;size&#39;] ." bytes<br />";
     print "temp name: ".$_FILES[&#39;fupload&#39;][&#39;tmp_name&#39;]   ."<br />";
     print "type: ".     $_FILES[&#39;fupload&#39;][&#39;type&#39;]       ."<br />";
     print "error: ".    $_FILES[&#39;fupload&#39;][&#39;error&#39;]      ."<br />";
 
     if ( $_FILES[&#39;fupload&#39;][&#39;type&#39;] == "image/gif" ) {
 
         $source = $_FILES[&#39;fupload&#39;][&#39;tmp_name&#39;];
         $target = "upload/".$_FILES[&#39;fupload&#39;][&#39;name&#39;];
         move_uploaded_file( $source, $target );// or die ("Couldn&#39;t copy");
         $size = getImageSize( $target );
 
         $imgstr = "<p><img width=\"$size[0]\" height=\"$size[1]\" ";
         $imgstr .= "src=\"$target\" alt=\"uploaded image\" /></p>";
 
         print $imgstr;
     }
 }
 ?>
 </div>
 <form enctype="multipart/form-data"
     action="<?php print $_SERVER[&#39;PHP_SELF&#39;]?>" method="post">
 <p>
 <input type="hidden" name="MAX_FILE_SIZE" value="102400" />
 <input type="file" name="fupload" /><br/>
 <input type="submit" value="upload!" />
 </p>
 </form>
 </body>
 </html>
声明:
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn