php图片文件上传详细分析

upload_err_ok              no error occurred.

上传成功
 
upload_err_ini_size        the uploaded file exceeds the maximum value specified in the php教程.ini file.
超出最大上传尺寸

upload_err_form_size       the uploaded file exceeds the maximum value specified by the max_file_size hidden widget.
超出form设置最大上传尺寸
 
upload_err_partial         the file upload was canceled and only part of the file was uploaded.
 
upload_err_nofile          no file was uploaded.

未上传文件

<html>
<head>
<title>a simple file upload form</title>
</head>
<body>
<form enctype="multipart/form-data"
   action="<?print $_server['php_self']?>" 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>

实例一

]<html>
 <head>
 <title>a file upload script</title>
 </head>
 <body>
 <div>
 <?php
 if ( isset( $_files['fupload'] ) ) {

     print "name: ".     $_files['fupload']['name']       ."<br />";
     print "size: ".     $_files['fupload']['size'] ." bytes<br />";
     print "temp name: ".$_files['fupload']['tmp_name']   ."<br />";
     print "type: ".     $_files['fupload']['type']       ."<br />";
     print "error: ".    $_files['fupload']['error']      ."<br />";

     if ( $_files['fupload']['type'] == "image/gif" ) {

         $source = $_files['fupload']['tmp_name'];
         $target = "upload/".$_files['fupload']['name'];
         move_uploaded_file( $source, $target );// or die ("couldn’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['php_self']?>" 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>

文件上传实例二

<?php
$maxsize=28480; 
if (!$http_post_vars['submit']) {
    $error=" ";
}
if (!is_uploaded_file($http_post_files['upload_file']['tmp_name']) and !isset($error)) {
    $error = "<b>you must upload a file!</b><br /><br />";
    unlink($http_post_files['upload_file']['tmp_name']);
}
if ($http_post_files['upload_file']['size'] > $maxsize and !isset($error)) {
    $error = "<b>error, file must be less than $maxsize bytes.</b><br /><br />";
    unlink($http_post_files['upload_file']['tmp_name']);
}
if (!isset($error)) {
    move_uploaded_file($http_post_files['upload_file']['tmp_name'],
                       "uploads/".$http_post_files['upload_file']['name']);
    print "thank you for your upload.";
    exit;
}
else
{
    echo ("$error");
}
?>

<html>
<head></head>
<body>
<form action="<?php echo(htmlspecialchars($_server['php_self']))?>"
method="post" enctype="multipart/form-data">
    choose a file to upload:<br />
    <input type="file" name="upload_file" size="80">
    <br />
    <input type="submit" name="submit" value="submit">
</form>
</body>
</html>

转载请注明:爱分享 » php图片文件上传详细分析

http://www.ihref.com/read-7059.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值