上传图片功能

WBOY
Release: 2016-06-23 13:33:29
Original
1001 people have browsed it

最近在弄上传图片的功能
我说下我的思路:将用户上传的文件保存到服务器上,获取图片路径加名字   再用img 显示出来

怎么过滤一起其他文件(.exe,.pdf,.txt.......)


回复讨论(解决方案)

获取mine类型。

strtolower(substr(strrchr($filename, '.'), 1, 10));
获取后缀名,判断

getimagesize() 函数将测定任何 GIF,JPG,PNG,SWF,SWC,PSD,TIFF,BMP,IFF,JP2,JPX,JB2,JPC,XBM 或 WBMP 图像文件的大小并返回图像的尺寸以及文件类型
还是这样的结果

Array(    [0] => 286    [1] => 314    [2] => 2    [3] => width="286" height="314"    [bits] => 8    [channels] => 3    [mime] => image/jpeg)
Copy after login

当 getimagesize() 返回空时就表示不是图片文件

上穿的时候,判断一下文件的扩展名,不是你想要的就不要上传

用户上传图片时,图片的长宽是不知道的,而我放图片框长宽又是固定的,这个要怎么解决?
(设置img的长度,小的图片被放大,大的被缩小,看起来怪怪的)

用户上传图片时,图片的长宽是不知道的,而我放图片框长宽又是固定的,这个要怎么解决?
(设置img的长度,小的图片被放大,大的被缩小,看起来怪怪的)



上传图片后,可以对图片做一个压缩处理。压缩到尺寸和你显示的一样就可以。
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!