谁能给我一段PHP上传图片和接收代码 谢谢
1个回答
展开全部
<?php
/*
===========================================================================
时间:2011-06-08
程序员:王源 QQ号:250578663
制作组:无限星空制组作
函数名:wenjianshangchuan();
功能:上传文件处理函数
参数:$file 上传的文件 $leixing 用户可以另传文件的其它格式
变量:string $$xswz 提示文字
return: string $fanhui 返回true 或 false
===========================================================================
*/
function wenjianshangchuan($file,$leixing=0){
$yxwj=array('png','gif','jpg','jpeg','bmp','tiff','ico');
if($leixing!=0){
$yxwj[]=$leixing;
}
$gangchuan=pathinfo($file['name']);
if($file['size']<=16000000){
if(in_array(strtolower($gangchuan['extension']),$yxwj)){
$uploaddir = $_SERVER['DOCUMENT_ROOT']."/uploades";
if(!is_dir($uploaddir)){
mkdir($uploaddir);
}
$uploaddir.="/".$gangchuan['filename'].mt_rand(1000,9999).".".$gangchuan['extension'];
if(move_uploaded_file($file['tmp_name'],$uploaddir)){
$xswz="<font color='#00FF00'>文件上传成功!</font>";
$fanhui=true;
}else{
$xswz="<font color='#FF0000'>文件大于2BM!文件上传失败!</font>";
$fanhui=false;
}
}else{
$xswz="<font color='#FF0000'>文件格式不正确!上传失败</font>";
$fanhui=false;
}
}else{
$xswz="<font color='#FF0000'>文件大于1BM!上传失败</font>";
$fanhui=false;
}
/*echo "<pre>";
print_r($gangchuan);
echo "</pre>";*/
echo $xswz;
return $fanhui;
}
if($_POST['subm_1']){
wenjianshangchuan($_FILES['file_1'],exe);
}
?><br /><br /><br /><br />
<form enctype="multipart/form-data" method="post" onsubmit="">
选择上传文件: <input type="file" name="file_1" /> 文件类型可以是:png, gif, jpg, jpeg, bmp, tiff, ico<br />
<input type="submit" name="subm_1" value="上传文件" />
</form>
0
| 评论
检举 | 2011-8-10 17:22 chenqiangmy | 三级
<?php
error_reporting(E_ALL & ~ E_NOTICE);
/*
* Created on 2011-7-23
*
* To change the template for this generated file go to
* Window - Preferences - PHPeclipse - PHP - Code Templates
*/
if(is_uploaded_file($_FILES['upfile']['tmp_name'])){
$upfile=$_FILES["upfile"];
$name=$upfile["name"];
$type=$upfile["type"];
$size=$upfile["size"];
$tmp_name=$upfile["tmp_name"];
$error=$upfile["error"];
}
//echo $name;
if($error=='0'){
move_uploaded_file($tmp_name,'upload/'.$name);
echo "上传成功!";
}
?>
<form action="upload.php" enctype="multipart/form-data" method="post" name="up">
上传文件:
<input name="upfile" type="file"/>
<input type="submit" value="上传"/><br/>
</form>
图片上传到php文件同目录下的upload文件夹下。若无需要新建,当然lz也可以自己设置move_uploaded_file($tmp_name,'upload/'.$name);。
/*
===========================================================================
时间:2011-06-08
程序员:王源 QQ号:250578663
制作组:无限星空制组作
函数名:wenjianshangchuan();
功能:上传文件处理函数
参数:$file 上传的文件 $leixing 用户可以另传文件的其它格式
变量:string $$xswz 提示文字
return: string $fanhui 返回true 或 false
===========================================================================
*/
function wenjianshangchuan($file,$leixing=0){
$yxwj=array('png','gif','jpg','jpeg','bmp','tiff','ico');
if($leixing!=0){
$yxwj[]=$leixing;
}
$gangchuan=pathinfo($file['name']);
if($file['size']<=16000000){
if(in_array(strtolower($gangchuan['extension']),$yxwj)){
$uploaddir = $_SERVER['DOCUMENT_ROOT']."/uploades";
if(!is_dir($uploaddir)){
mkdir($uploaddir);
}
$uploaddir.="/".$gangchuan['filename'].mt_rand(1000,9999).".".$gangchuan['extension'];
if(move_uploaded_file($file['tmp_name'],$uploaddir)){
$xswz="<font color='#00FF00'>文件上传成功!</font>";
$fanhui=true;
}else{
$xswz="<font color='#FF0000'>文件大于2BM!文件上传失败!</font>";
$fanhui=false;
}
}else{
$xswz="<font color='#FF0000'>文件格式不正确!上传失败</font>";
$fanhui=false;
}
}else{
$xswz="<font color='#FF0000'>文件大于1BM!上传失败</font>";
$fanhui=false;
}
/*echo "<pre>";
print_r($gangchuan);
echo "</pre>";*/
echo $xswz;
return $fanhui;
}
if($_POST['subm_1']){
wenjianshangchuan($_FILES['file_1'],exe);
}
?><br /><br /><br /><br />
<form enctype="multipart/form-data" method="post" onsubmit="">
选择上传文件: <input type="file" name="file_1" /> 文件类型可以是:png, gif, jpg, jpeg, bmp, tiff, ico<br />
<input type="submit" name="subm_1" value="上传文件" />
</form>
0
| 评论
检举 | 2011-8-10 17:22 chenqiangmy | 三级
<?php
error_reporting(E_ALL & ~ E_NOTICE);
/*
* Created on 2011-7-23
*
* To change the template for this generated file go to
* Window - Preferences - PHPeclipse - PHP - Code Templates
*/
if(is_uploaded_file($_FILES['upfile']['tmp_name'])){
$upfile=$_FILES["upfile"];
$name=$upfile["name"];
$type=$upfile["type"];
$size=$upfile["size"];
$tmp_name=$upfile["tmp_name"];
$error=$upfile["error"];
}
//echo $name;
if($error=='0'){
move_uploaded_file($tmp_name,'upload/'.$name);
echo "上传成功!";
}
?>
<form action="upload.php" enctype="multipart/form-data" method="post" name="up">
上传文件:
<input name="upfile" type="file"/>
<input type="submit" value="上传"/><br/>
</form>
图片上传到php文件同目录下的upload文件夹下。若无需要新建,当然lz也可以自己设置move_uploaded_file($tmp_name,'upload/'.$name);。
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询