快捷搜索:   nginx

图片上传代码(经典)

上传页:

-------------------------------------------------------------------------------------------------------------------------

/* 网页顶部加上如下代码*/

<?php
$uptypes = array(
    'image/jpg',
    'image/jpeg',
    'image/png',
    'image/pjpeg',
    'image/gif',
    'image/bmp',
    'image/x-png'
);
?>

/*网页合适位置加上如下上传前台代码*/

<form enctype="multipart/form-data" name="upImage_form" action="chuli.php" method="post">
<table>
<tr>
<td>图片上传:
<input name="upfile" type="file" style="width:200;border:1 solid #9a9999; font-size:9pt; background-color:#ffffff" size="17">

<input name="Submit" type="submit" value="上传" style="width:30;border:1 solid #9a9999; font-size:9pt; background-color:#ffffff" size="17"><br><br><br>

<span class="red"><b>注意:</b></span> 上传图片不能大于500KB </td>
</tr>
</table>
</form>

------------------------------------------------------------------------------------------------------------------------------

第二页 chuli.php

<?php
if($_POST['Submit']=='上传'){

$file        = $_FILES["upfile"];
$fname         = $_FILES["upfile"]["name"];
$fname_array   = explode('.',$fname);
$extend        = $fname_array[count($fname_array)-1];
$MAX_FILE_SIZE = 512000;
//文件当前位置创建picture文件夹,若要在上一层目录创建则为"../picture/";
$dest_folder   = "picture/";
if($extend!=""){

if($file["size"]>$MAX_FILE_SIZE){
      echo "图片大小不能超过512KB!";
   exit;
}
if(!file_exists($dest_folder)){
           mkdir($dest_folder);
}
$randval    = date('Ymd').rand();
$uploadfile = $dest_folder.$randval.'.'.$extend;
echo '图片: '.$uploadfile ;
if(move_uploaded_file($_FILES["upfile"]["tmp_name"],$uploadfile)){
   echo "图片上传成功!";
}else{
   echo "图片上传失败!";
}
}

/*以下只是针对个别网站,写出图片的地址*/


$url="http://www.xrwire.com/auto/auto/mm/";
echo "<br>";
echo "图片的URL是:";
echo "&nbsp;&nbsp;";
echo $url ;
echo $uploadfile ;
}
?>


顶(0)
踩(0)

您可能还会对下面的文章感兴趣:

最新评论