没有样式,没有淘宝的那种放大截取大小的效果,只是实现了图片上传的功能。 图片超过100k,会出现内部错误服务器错误,需要手动更改配置文件里的MaxRequestLen属性。 下面粘上代码: 1 ? php 2 /* ********************************************************
没有样式,没有淘宝的那种放大截取大小的效果,只是实现了图片上传的功能。
图片超过100k,会出现内部错误服务器错误,需要手动更改配置文件里的MaxRequestLen属性。
下面粘上代码:
<span> 1</span> <span>php </span><span> 2</span> <span>/*</span><span>***************************************************************************** </span><span> 3</span> <span> 4</span> <span>参数说明: </span><span> 5</span> <span>$max_file_size : 上传文件大小限制, 单位BYTE </span><span> 6</span> <span>$destination_folder : 上传文件路径 </span><span> 7</span> <span>$watermark : 是否附加水印(1为加水印,其他为不加水印); </span><span> 8</span> <span> 9</span> <span>*****************************************************************************</span><span>*/</span> <span> 10</span> <span> 11</span> <span>//</span><span>上传文件类型列表</span> <span> 12</span> <span>$uptypes</span>=<span>array</span><span>( </span><span> 13</span> 'image/jpg', <span> 14</span> 'image/jpeg', <span> 15</span> 'image/png', <span> 16</span> 'image/pjpeg', <span> 17</span> 'image/gif', <span> 18</span> 'image/bmp', <span> 19</span> 'image/x-png' <span> 20</span> <span>); </span><span> 21</span> <span> 22</span> <span>$max_file_size</span>=102400; <span>//</span><span>上传文件大小限制, 单位BYTE</span> <span> 23</span> <span>$destination_folder</span>="uploadimg/"; <span>//</span><span>上传文件路径</span> <span> 24</span> <span>$watermark</span>=1; <span>//</span><span>是否附加水印(1为加水印,其他为不加水印);</span> <span> 25</span> <span>$watertype</span>=1; <span>//</span><span>水印类型(1为文字,2为图片)</span> <span> 26</span> <span>$waterposition</span>=1; <span>//</span><span>水印位置(1为左下角,2为右下角,3为左上角,4为右上角,5为居中);</span> <span> 27</span> <span>$waterstring</span>="http://www.xplore.cn/"; <span>//</span><span>水印字符串</span> <span> 28</span> <span>$waterimg</span>="xplore.gif"; <span>//</span><span>水印图片</span> <span> 29</span> <span>$imgpreview</span>=1; <span>//</span><span>是否生成预览图(1为生成,其他为不生成);</span> <span> 30</span> <span>$imgpreviewsize</span>=1/2; <span>//</span><span>缩略图比例</span> <span> 31</span> ?> <span> 32</span> <span> 33</span> <span> 34</span> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> <span> 35</span> <title>php上传图片</title> <span> 36</span> <span> 37</span> <span> 38</span> <span> 39</span> <span> 40</span>47 48 php 49 if ($_SERVER['REQUEST_METHOD'] == 'POST') 50 { 51 $file = $_FILES["upfile"]; 52 if($max_file_size >= $file["size"] && in_array($file["type"], $uptypes) && file_exists($destination_folder) && is_uploaded_file($_FILES["upfile"]['tmp_name'])) 53 { 54 55 $filename=$file["tmp_name"];//图片的临时名称 56 $image_size = getimagesize($filename);//图片大小 57 $pinfo=pathinfo($file["name"]);//返回包含dirname,basename 和 extension的url 58 $ftype=$pinfo['extension'];//图片类型,后缀名 59 $destination = $destination_folder.time().".".$ftype;//目标图片的名称 60 if (file_exists($destination) && $overwrite != true) 61 { 62 echo "同名文件已经存在了"; 63 exit; 64 } 65 66 if(!move_uploaded_file ($filename, $destination)) 67 { 68 echo "移动文件出错"; 69 exit; 70 } 71 72 $pinfo=pathinfo($destination);//返回包含dirname,basename 和 extension的url 73 $fname=$pinfo['basename'];//目标图片的名称包含后缀名 74 echo " 已经成功上传