在php中上传文件,比java中简单多了,因为有一个 global $_FILES
HTTP File upload variables: $_FILES
Note: Introduced in 4.1.0. In earlier versions, use $HTTP_POST_FILES.
An associative array of items uploaded to the current script via the HTTP POST method. Automatically global in any scope.
This is a 'superglobal', or automatic global, variable. This simply means that it is available in all scopes throughout a script. You don't need to do a global $_FILES; to access it within functions or methods, as you do with $HTTP_POST_FILES.
$HTTP_POST_FILES contains the same information, but is not a superglobal. (Note that $HTTP_POST_FILES and $_FILES are different variables and that PHP handles them as such)
相信大家都应该看到明白的了,
再看一下var_export($_FILES)的结果:
array ( 'file_img' => array ( 'name' => 'image000.jpg', 'type' => 'image/pjpeg', 'tmp_name' => 'C:\\WINDOWS\\TEMP\\php66.tmp', 'error' => 0, 'size' => 77332, ), )
这是上传单个文件的结果, 'file_img' 是一个input,
可以看到上传的文件的一些重要的属性, 再看以下代码]
$fname = $_FILES['file_img']['name'];
$ftmp = $_FILES['file_img']['tmp_name'];
$p1 = "../wp-content/";
@mkdir( $p1 );
$p1 = "../wp-content/uploads/";
@mkdir( $p1 );
$p1 = "../wp-content/uploads/" . date('Ym') . "/";
@mkdir( $p1 );
$newname = date('Ymdhis') . substr( $fname, strrpos($fname, '.') );
//var_export($_FILES);
copy( $ftmp, $p1 . $newname);
上传后, 由tmp_name的值可知,是放到缓冲区中的, 我们要将上传后的文件还原放到指定期的目录,就必须要
利用其它的几个属性, 使用 copy 的方法把缓冲区的文件copy到指定的位置.




















