Maison > php教程 > php手册 > PHP 头像上传,php头像上传

PHP 头像上传,php头像上传

WBOY
Libérer: 2016-06-13 09:17:49
original
1058 Les gens l'ont consulté

PHP 头像上传,php头像上传

          嘻嘻,自从圣诞节过后,就一直懒散,这几天也因为是太过于繁忙的原因,感觉好久都没有出来冒冒泡,诶...

          为了生活一直在奋斗,作为一名前端开发工程师,我现在越来越迷茫了,都不知道现在自己到底算什么了?

         会html5和从css3 是前端?

         会php 是前端?

         会smarty 是前端?

         会javascript是前端?

         会jQuery 是前端?

         会Ajax 是前端?

         会各种框架是前端?

         总之现在越来越感觉自己不是一个前端人员了,学得多,用的杂,这难道就是前端的命运?

 

        网站前端:

              前端对于网站来说,通常是指,网站的前台部分包括网站的表现层和结构层。因此前端技术一般分为前端设计和前端开发,前端设计一般可以理解为网站的视觉设计, 前端开发则是网站的前台代码实现,包括基本的HTML和CSS以及JavaScript/ajax,现在最新的高级版本是HTML5、CSS3,以及SVG等。

    

     最近接触到了一些php的东西,感觉还不错,所以还是与大家分享一下吧!

   

      php头像上传:

1、html

<span><</span><span>html</span><span>></span>  
<span><</span><span>head</span><span>></span>  
<span><</span><span>title</span><span>></span>图片上传<span></</span><span>title</span><span>></span>  
<span><</span><span>style </span><span>type</span><span>="text/css"</span><span>></span><span> 
body  
    </span><span>{</span><span>font-size</span><span>:</span><span> 14px</span><span>;</span><span>}</span>  
<span></</span><span>style</span><span>></span>  
<span></</span><span>head</span><span>></span>  
  
<span><</span><span>body</span><span>></span>  
<span><</span><span>form </span><span>enctype</span><span>="multipart/form-data"</span><span> method</span><span>="post"</span><span> name</span><span>="upform"</span><span>></span><span>  
  上传文件:  
  </span><span><</span><span>input </span><span>name</span><span>="upfile"</span><span> type</span><span>="file"</span><span>></span>  
  <span><</span><span>input </span><span>type</span><span>="submit"</span><span> value</span><span>="上传"</span><span>><</span><span>br</span><span>></span>  
   
<span></</span><span>form</span><span>></span> 
Copier après la connexion


2、php 上传头像

<?<span>php
 </span><span>//</span><span>上传文件类型列表  </span>
<span>$uptypes</span>=<span>array</span><span>(  
    </span>'image/jpg',  
    'image/jpeg',  
    'image/png',  
    'image/pjpeg',  
    'image/gif',  
    'image/bmp',  
    'image/x-png'<span>  
);

</span><span>$max_file_size</span>=2000000;     <span>//</span><span>上传文件大小限制, 单位BYTE  </span>
<span>$destination_folder</span>="uploadimg/"; <span>//</span><span>上传文件路径  </span>
<span>$cun</span>="../../images/uploadimg/"<span>;
</span><span>$imgpreview</span>=1;      <span>//</span><span>是否生成预览图(1为生成,其他为不生成);  </span>
<span>$imgpreviewsize</span>=1/2;    <span>//</span><span>缩略图比例  </span>

?>
Copier après la connexion

简单的定义了一下对于图片上传的格式以及其他的一些参数,

3、具体的判断方法

<?<span>php  
</span><span>if</span> (<span>$_SERVER</span>['REQUEST_METHOD'] == 'POST'<span>)  
 {  
     </span><span>if</span> (!<span>is_uploaded_file</span>(<span>$_FILES</span>["upfile"<span>][tmp_name]))  
     </span><span>//</span><span>是否存在文件  </span>
<span>     {  
         </span><span>echo</span> "图片不存在!"<span>;  
         </span><span>exit</span><span>;  
     }  
  
    </span><span>$file</span> = <span>$_FILES</span>["upfile"<span>];  
    </span><span>if</span>(<span>$max_file_size</span> < <span>$file</span>["size"<span>])  
    </span><span>//</span><span>检查文件大小  </span>
<span>    {  
        </span><span>echo</span> "文件太大!"<span>;  
        </span><span>exit</span><span>;  
    }  
  
    </span><span>if</span>(!<span>in_array</span>(<span>$file</span>["type"], <span>$uptypes</span><span>))  
    </span><span>//</span><span>检查文件类型  </span>
<span>    {  
        </span><span>echo</span> "文件类型不符!".<span>$file</span>["type"<span>];  
        </span><span>exit</span><span>;  
    }  
  
    </span><span>if</span>(!<span>file_exists</span>(<span>$destination_folder</span><span>))  
    {  
        </span><span>mkdir</span>(<span>$destination_folder</span><span>);  
    }  
  
    </span><span>$filename</span>=<span>$file</span>["tmp_name"<span>];  
    </span><span>$image_size</span> = <span>getimagesize</span>(<span>$filename</span><span>);  
    </span><span>$pinfo</span>=<span>pathinfo</span>(<span>$file</span>["name"<span>]);  
    </span><span>$ftype</span>=<span>$pinfo</span>['extension'<span>];  
    </span><span>$destination</span> = <span>$destination_folder</span>.<span>time</span>().".".<span>$ftype</span><span>;  
    </span><span>if</span> (<span>file_exists</span>(<span>$destination</span>) && <span>$overwrite</span> != <span>true</span><span>)  
    {  
        </span><span>echo</span> "同名文件已经存在了"<span>;  
        </span><span>exit</span><span>;  
    }  
  
    </span><span>if</span>(!<span>move_uploaded_file</span> (<span>$filename</span>, <span>$destination</span><span>))  
    {  
        </span><span>echo</span> "移动文件出错"<span>;  
        </span><span>exit</span><span>;  
    }  
  
    </span><span>if</span>(<span>$imgpreview</span>==1<span>)  
    {  
    </span><span>echo</span> "<br>图片预览:<br>"<span>;  
    </span><span>echo</span> "<img  src=\"".<span alt="PHP  头像上传,php头像上传" >$destination</span>."\" width=".(<span>$image_size</span>[0]*<span>$imgpreviewsize</span>)." height=".(<span>$image_size</span>[1]*<span>$imgpreviewsize</span><span>);  
    </span><span>echo</span> " alt=\"图片预览:\r文件名:".<span>$destination</span>."\r上传时间:\">"<span>;  
    }  
  }
</span>?>  
Copier après la connexion

 

 反正也是瞎猫碰上死耗子,也是这么任性的效果就出来了,嘻嘻, 其中图片生成的储存路径是一个关键,注意一下就好了!

 

        

 

Étiquettes associées:
source:php.cn
Déclaration de ce site Web
Le contenu de cet article est volontairement contribué par les internautes et les droits d'auteur appartiennent à l'auteur original. Ce site n'assume aucune responsabilité légale correspondante. Si vous trouvez un contenu suspecté de plagiat ou de contrefaçon, veuillez contacter admin@php.cn
Recommandations populaires
Tutoriels populaires
Plus>
Derniers téléchargements
Plus>
effets Web
Code source du site Web
Matériel du site Web
Modèle frontal