php实现图片上传与文件上传的实现代码实例
2011-04-26 11:20
1416 查看
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=" ";//www.3ppt.com
}
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>
上传成功
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=" ";//www.3ppt.com
}
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+ajax实现图片文件上传实例代码
- php结合Ajax实现异步文件上传的代码实例
- 利用discuz实现PHP大文件上传应用实例代码
- php中通过Ajax如何实现异步文件上传的代码实例
- php实现文件上传功能的代码实例
- php实现上传图片文件代码
- PHP 图片文件上传实现代码
- 服务器基于PHP CodeIgniter,Android基于Volley实现多文件/图片上传(含服务器,web版和android客户端完整代码)
- php+ajax实现图片文件上传功能实例
- PHP 图片文件上传实现代码
- php实现上传图片文件代码
- PHP swfupload图片文件上传实例代码
- php结合Ajax如何实现异步文件上传的代码实例
- php实现base64图片上传方式实例代码
- 利用discuz实现PHP大文件上传应用实例代码
- php实现文件上传功能的详细代码实例
- PHP 图片文件上传实现代码
- php中通过Ajax如何实现异步文件上传的代码实例
- php下连接ftp实现文件的上传、下载、删除文件实例代码
- PHP实现文件上传功能实例代码