這是我在做的一個系統中的新聞增加程式,可以上傳圖片,也可以輸入絕對大於4K的內容(在textarea中),...

來源:互聯網
上載者:User
程式|上傳|上傳圖片 <?php
/*******所用到的表結構********
DROP TABLE IF EXISTS index_news;
CREATE TABLE index_news (
   news_id bigint(20) NOT NULL auto_increment,
   news_date date DEFAULT '0000-00-00' NOT NULL,
   news_title varchar(100) NOT NULL,
   news_content text,
   news_link varchar(100),
   is_new char(1) DEFAULT '1',
   picture_id int(11),
   picture_side char(1) DEFAULT '1',
   news_show char(1) DEFAULT '1',
   PRIMARY KEY (news_id),
   KEY id (news_id)
);
DROP TABLE IF EXISTS picture;
CREATE TABLE picture (
   id int(11) NOT NULL auto_increment,
   picture blob NOT NULL,
   picture_type varchar(50) NOT NULL,
   PRIMARY KEY (id),
   UNIQUE id (id)
);
**********************/
require("../include/date.inc.php3");
require("../include/config.inc.php3");
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">

<html>
<head>
<title>修改首頁新聞資訊</title>
<script language="JavaScript">
<!--
function MM_findObj(n, d) { //v3.0
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document); return x;
}

function MM_validateForm() { //v3.0
  var i,p,q,nm,test,num,min,max,errors='',args=MM_validateForm.arguments;
  for (i=0; i<(args.length-2); i+=3) { test=args[i+2]; obj_name=args[i+1]; val=MM_findObj(args[i]);
    if (val) { nm=val.name; if ((val=val.value)!="") {
      if (test.indexOf('isEmail')!=-1) { p=val.indexOf('@');
        if (p<1 || p==(val.length-1)) errors+='- '+obj_name+' 必須是一個E-Mail地址.\n';
      } else if (test!='R') { num = parseFloat(val);
        if (val!=''+num) errors+='- '+obj_name+' 必須是一個數字.\n';
        if (test.indexOf('inRange') != -1) { p=test.indexOf(':');
          min=test.substring(8,p); max=test.substring(p+1);
          if (num<min || max<num) errors+='- '+obj_name+' 必須是一個在 '+min+' 和 '+max+'之間的數字.\n';
    } } } else if (test.charAt(0) == 'R') errors += '- '+obj_name+' 必須輸入.\n'; }
  } if (errors) alert('輸入資料存在錯誤:\n'+errors);
  document.MM_returnValue = (errors == '');
}
//-->
</script>
</head>

<body>
<?php
if ($add){
    $date=input2date($news_date);
    //echo $picture . "  ". filesize($picture);
    //if ($is_new!="0") $is_new="1" ;
    //if ($news_show!="0") $news_show="1";
    //if ($picture_side!="2") $picture_side="1";
    if ($picture!="none"){
        $pic_data = addslashes(fread($fp=fopen($picture,"r"), filesize($picture)));
        $i_str="insert into picture (picture,picture_type) values ('$pic_data','$picture_type')";
        //$rs->open($i_str);
        $result=mysql_query($i_str,$dbconnect);
        $picture_id=mysql_insert_id();
        fclose($fp);
        unlink($picture);
    }
    else{
        $picture_id=0 ;
    }
    $i_str="insert into index_news (news_date,news_title,news_content,news_link,picture_id,is_new,picture_side,news_show) values ";
    $i_str.="('$date','$news_title','$news_content','$news_link','$picture_id','$is_new','$picture_side','$news_show') ";

    if (mysql_query($i_str,$dbconnect)) echo "已添加!";

}

<form name="F" enctype="multipart/form-data" method="post" action="<?php echo $PATH_INFO; ?>" >
  <table width="500" border="0" cellspacing="0" cellpadding="0" align="center">
    <tr>
      <td colspan="2">
        <div align="center"><font size="4">增加新聞資訊</font></div>
      </td>
    </tr>
    <tr>
      <td colspan="2">  </td>
    </tr>
    <tr>
      <td width="100">新聞標題: </td>
      <td>
        <input type="text" name="news_title" size="60">
      </td>
    </tr>
    <tr>
      <td>新聞內容:</td>
      <td>
        <textarea name="news_content" cols="58" rows="5"></textarea>
      </td>
    </tr>
    <tr>
      <td>新聞日期:</td>
      <td>
        <input type="text" name="news_date">
        (日期請按照2000-01-02格式輸入) </td>
    </tr>
    <tr>
      <td>新聞連結:</td>
      <td>
        <input type="text" name="news_link" size="60">
      </td>
    </tr>
    <tr>
      <td>是否最新:</td>
      <td>
        <select name="is_new">
          <option value="1" selected>是最新</option>
          <option value="0">不是最新</option>
        </select>
      </td>
    </tr>
    <tr>
      <td>新聞圖片:</td>
      <td>
        <input type="file" name="picture" size="50">
      </td>
    </tr>
    <tr>
      <td>圖片位置:</td>
      <td>
        <select name="picture_side">
          <option value="1" selected>左邊</option>
          <option value="2">右邊</option>
        </select>
      </td>
    </tr>
    <tr>
      <td>是否顯示:</td>
      <td>
        <select name="news_show">
          <option value="1" selected>顯示</option>
          <option value="0">不顯示</option>
        </select>
      </td>
    </tr>
    <tr>
      <td colspan="2">
        <div align="center">
          <input type="submit" name="add" value="增加" onClick="MM_validateForm('news_title','','R','news_date','','R','news_content','','R');return document.MM_returnValue">
          <input type="button" name="return" value="返回">
          <input type="reset" name="reset" value="重新輸入">
        </div>
      </td>
    </tr>
  </table>
  </form>
</body>
</html>

相關文章

Beyond APAC's No.1 Cloud

19.6% IaaS Market Share in Asia Pacific - Gartner IT Service report, 2018

Learn more >

Apsara Conference 2019

The Rise of Data Intelligence, September 25th - 27th, Hangzhou, China

Learn more >

Alibaba Cloud Free Trial

Learn and experience the power of Alibaba Cloud with a free trial worth $300-1200 USD

Learn more >

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。