php文件上传程序
文章提供一款完整理的php文件上传程序实例代码,他可以上传图片并且把图片保存到1:按天存入目录 2:按月存入目录 ,还可以设置上传图片生成水印.
- <!doctype html public "-//w3c//dtd xhtml 1.0 transitional//en" "http://www.w3.org/tr/xhtml1/dtd/xhtml1-transitional.dtd">
- <html xmlns="http://www.w3.org/1999/xhtml">
- <head>
- <meta http-equiv="content-type" content="text/html; charset=gb2312" />
- <title>上传文件程序</title>
- <style type="text/css">
- *{
- font-size:12px;
- margin:0; padding:0;
- }
- a:link,a:visited{
- text-decoration:none;
- color: #393
- }
- a:hover{
- text-decoration:underline;
- color:#0033cc
- }
- input.text{
- border:1px solid #ccc;height:22px;line-height:22px;padding-left:5px;background:#fff;width:274px;
- }
- input.button{
- background:#fff url(images/button.png);border:1px solid #9ea9c5;padding:2px 2px 0px 2px;margin-left:4px; margin-right:4px;
- }
- </style>
- <script language=javascript>
- function check()
- {
- var strfilename=document.myform.upfile.value;
- if (strfilename=="")
- {
- alert("请选择要上传的文件");
- document.myform.upfile.focus();
- return false;
- }
- }
- </script>
- </head>
- <body>
- <?php
-
-
-
-
- include("common/upfiles.class.php");
- $path="../upload/coolsite";
- $mix="smallimg";
- $mark="markimg";
- $text = array("www.111cn.net");
- $oupload= new upfiles($path,$mix,$mark);
- if(isset($_post['up'])){
-
- if($_post['urlid']=='1'){
-
- $oupload->tofile = true;
- $photo = $oupload->upload("upfile");
- $photourl = $oupload->fileurl."/".$photo;
- $newsmallimg = $oupload->smallimg($photo);
-
-
-
-
-
- }else{
- $upfilename = $oupload->upload("upfile");
- }
- $strjs = "<script language=javascript>n";
- $strjs .= "parent.document.myform.upfile1.value='".$newsmallimg."'n";
- $strjs .= "parent.document.myform.upfile2.value='".$photourl."'n";
- $strjs .= "</script>n";
- echo $strjs;
- }