導航:首頁 > 源碼編譯 > php在線表單源碼

php在線表單源碼

發布時間:2022-10-21 11:46:12

php文件執行時顯示源代碼

<form action="access_cars.php" method="post"> 按樓主這么寫,你的 access_cars.php 應該放在表單這個html同一個文件夾下,且這個文件夾裡面可以運行php的

② 用PHP做一個簡單的表單

在index.php中加上header("refresh:0;url=index.php?a=".$a "& b=".$b....);//跳轉頁面,注意路徑
然後在要跳轉的頁面接受Url傳遞的參數為自己所用isset($_GET["a"])

③ 把PHP的表單提交到伺服器端上並保存到文本文件,源碼怎麼寫

直接用fopen()就可以

④ 求php文件上傳源碼

<?php
//文件和圖片上傳類
class UploadFile
{//類定義開始
public $maxSize = -1; // 上傳文件的最大值
public $supportMulti = true; // 是否支持多文件上傳
public $allowExts = array();// 允許上傳的文件後綴// 留空不作後綴檢 查
public $allowTypes = array(); // 允許上傳的文件類型 // 留空不做檢查
public $thumb = false; // 使用對上傳圖片進行縮略圖處理
public $thumbMaxWidth; // 縮略圖最大寬度
public $thumbMaxHeight; // 縮略圖最大高度
public $thumbPrefix = 'thumb_'; // 縮略圖前綴
public $thumbSuffix = '';
public $thumbPath = ''; // 縮略圖保存路徑
public $thumbFile = '';// 縮略圖文件名
public $thumbRemoveOrigin =false;// 是否移除原圖
public $zipImages = false; // 壓縮圖片文件上傳
public $autoSub = false; // 啟用子目錄保存文件
public $subType = 'hash';// 子目錄創建方式 可以使用hash date
public $dateFormat = 'Ymd';
public $hashLevel = 1; // hash的目錄層次
public $savePath = ''; // 上傳文件保存路徑
public $autoCheck = true; // 是否自動檢查附件
public $uploadReplace = false;// 存在同名是否覆蓋
// 例如可以是 time uniqid com_create_guid 等
// 必須是一個無需任何參數的函數名 可以使用自定義函數
public $saveRule = '';// 上傳文件命名規則
// 例如可以是 md5_file sha1_file 等// 上傳文件Hash規則函數名
public $hashType = 'md5_file';
private $error = '';// 錯誤信息
private $uploadFileInfo ;// 上傳成功的文件信息
/**
+----------------------------------------------------------
* 架構函數
+----------------------------------------------------------
* @access public
+----------------------------------------------------------
*/
public function __construct($maxSize='',$allowExts='',$allowTypes='',$savePath='',$saveRule='')
{
if(!empty($maxSize) && is_numeric($maxSize)) {
$this->maxSize = $maxSize;
}
if(!empty($allowExts)) {
if(is_array($allowExts)) {
$this->allowExts = array_map('strtolower',$allowExts);
}else {
$this->allowExts = explode(',',strtolower($allowExts));
}
}
if(!empty($allowTypes)) {
if(is_array($allowTypes)) {
$this->allowTypes = array_map('strtolower',$allowTypes);
}else {
$this->allowTypes = explode(',',strtolower($allowTypes));
}
}
if(!empty($savePath)) {
$this->savePath = $savePath;
}
if(!empty($saveRule)) {
$this->saveRule = $saveRule;
}

}

private function save($file)
{
$filename = $file['savepath'].$file['savename'];
if(!$this->uploadReplace && is_file($filename)) {// 不覆蓋同名文件
$this->error = '文件已經存在!'.$filename;
return $this -> error;
}
// 如果是圖像文件 檢測文件格式
if( in_array(strtolower($file['extension']),array('gif','jpg','jpeg','bmp','png','swf')) && $this -> error === getimagesize($file['tmp_name'])) {
$this->error = '非法圖像文件';
return $this -> error;
}
if(!move_uploaded_file($file['tmp_name'], iconv('utf-8','gbk',$filename))) {
$this->error = '文件上傳保存錯誤!';
return $this -> error;
}
if($this->thumb && in_array(strtolower($file['extension']),array('gif','jpg','jpeg','bmp','png'))) {
$image = getimagesize($filename);
if($this -> error !== $image) {
//是圖像文件生成縮略圖
$thumbWidth = explode(',',$this->thumbMaxWidth);
$thumbHeight = explode(',',$this->thumbMaxHeight);
$thumbPrefix = explode(',',$this->thumbPrefix);
$thumbSuffix = explode(',',$this->thumbSuffix);
$thumbFile = explode(',',$this->thumbFile);
$thumbPath =
$this->thumbPath?$this->thumbPath:$file['savepath'];
// 生成圖像縮略圖
if(file_exists(dirname(__FILE__).'/Image.class.php'))
{
require_once(dirname(__FILE__).'/Image.class.php');
$realFilename = $this->autoSub?basename($file['savename']):$file['savename'];
for($i=0,$len=count($thumbWidth); $i<$len; $i++) {
$thumbname = $thumbPath.$thumbPrefix[$i].substr($realFilename,0,strrpos($realFilename, '.')).$thumbSuffix[$i].'.'.$file['extension'];
Image::thumb($filename,$thumbname,'',$thumbWidth[$i],$thumbHeight[$i],true);
}
if($this->thumbRemoveOrigin) {
// 生成縮略圖之後刪除原圖
unlink($filename);
}
}
}
}

return true;
}

/**
+----------------------------------------------------------
* 上傳文件
+----------------------------------------------------------
* @access public
+----------------------------------------------------------
* @param string $savePath 上傳文件保存路徑
+----------------------------------------------------------
* @return string
+----------------------------------------------------------
* @throws ThinkExecption
+----------------------------------------------------------
*/
public function upload($savePath ='') {

if(empty($savePath)) //如果不指定保存文件名,則由系統默認
$savePath = $this->savePath;
$savePath .= date('Ym',time())."/";
if(!is_dir($savePath)) { // 檢查上傳目錄

if(is_dir(base64_decode($savePath))) {// 檢查目錄是否編碼後的
$savePath = base64_decode($savePath);
}else{
if(!mkdir($savePath)){ // 嘗試創建目錄
$this->error = '上傳目錄'.$savePath.'不存在';return $this -> error;
}
}
}else {
if(!is_writeable($savePath)) {
$this->error = '上傳目錄'.$savePath.'不可寫'; return $this -> error;
}
}
$fileInfo = array();
$isUpload = $this -> error;

// 獲取上傳的文件信息
// 對$_FILES數組信息處理
$files = $this->dealFiles($_FILES);
foreach($files as $key => $file) {
//過濾無效的上傳
if(!empty($file['name'])) {
//登記上傳文件的擴展信息
$file['key'] = $key;
$file['extension'] = $this->getExt($file['name']);
$file['savepath'] = $savePath;
$file['savename'] = $this->getSaveName($file);

// 自動檢查附件
if($this->autoCheck) {
if(!$this->check($file))
return $this -> error;
}

//保存上傳文件
//echo "<pre>";print_r( $file );
if(!$this->save($file)) return $this -> error;
/*
if(function_exists($this->hashType)) {
$fun = $this->hashType;
$file['hash'] = $fun(auto_charset($file['savepath'].$file['savename'],'utf-8','gbk'));
}
*/
//上傳成功後保存文件信息,供其他地方調用
unset($file['tmp_name'],$file['error']);
$fileInfo[] = $file;
$isUpload = true;
}
}
if($isUpload) {
$this->uploadFileInfo = $fileInfo;
return $fileInfo;
}else {
$this->error = '沒有選擇上傳文件';
return $this -> error;
}
}

/**
+----------------------------------------------------------
* 轉換上傳文件數組變數為正確的方式
+----------------------------------------------------------
* @access private
+----------------------------------------------------------
* @param array $files 上傳的文件變數
+----------------------------------------------------------
* @return array
+----------------------------------------------------------
*/
private function dealFiles($files) {
$fileArray = array();
foreach ($files as $file){
if(is_array($file['name'])) {
$keys = array_keys($file);
$count = count($file['name']);
for ($i=0; $i<$count; $i++) {
foreach ($keys as $key)
$fileArray[$i][$key] = $file[$key][$i];
}
}else{
$fileArray = $files;
}
break;
}
return $fileArray;
}

/**
+----------------------------------------------------------
* 獲取錯誤代碼信息
+----------------------------------------------------------
* @access public
+----------------------------------------------------------
* @param string $errorNo 錯誤號碼
+----------------------------------------------------------
* @return void
+----------------------------------------------------------
* @throws ThinkExecption
+----------------------------------------------------------
*/
protected function error($errorNo)
{
switch($errorNo) {
case 1:
$this->error = '上傳的文件超過了 php.ini 中 upload_max_filesize 選項限制的值';
break;
case 2:
$this->error = '上傳文件的大小超過了 HTML 表單中 MAX_FILE_SIZE 選項指定的值';
break;
case 3:
$this->error = '文件只有部分被上傳';
break;
case 4:
$this->error = '沒有文件被上傳';
break;
case 6:
$this->error = '找不到臨時文件夾';
break;
case 7:
$this->error = '文件寫入失敗';
break;
default:
$this->error = '未知上傳錯誤!';
}
return ;
}

/**
+----------------------------------------------------------
* 根據上傳文件命名規則取得保存文件名
+----------------------------------------------------------
* @access private
+----------------------------------------------------------
* @param string $filename 數據
+----------------------------------------------------------
* @return string
+----------------------------------------------------------
*/
private function getSaveName($filename)
{
$rule = $this->saveRule;
if(empty($rule)) {//沒有定義命名規則,則保持文件名不變
$saveName = $filename['name'];
}else {
if(function_exists($rule)) {
//使用函數生成一個唯一文件標識號
$saveName = $rule().rand(1001,9999).".".$filename['extension'];
}else {
//使用給定的文件名作為標識號
$saveName = $rule.rand(1001,9999).".".$filename['extension'];
}
}
if($this->autoSub) {
// 使用子目錄保存文件
$saveName = $this->getSubName($filename).'/'.$saveName;
}
return $saveName;
}

/**
+----------------------------------------------------------
* 獲取子目錄的名稱
+----------------------------------------------------------
* @access private
+----------------------------------------------------------
* @param array $file 上傳的文件信息
+----------------------------------------------------------
* @return string
+----------------------------------------------------------
*/
private function getSubName($file)
{
switch($this->subType) {
case 'date':
$dir = date($this->dateFormat,time());
break;
case 'hash':
default:
$name = md5($file['savename']);
$dir = '';
for($i=0;$i<$this->hashLevel;$i++) {
$dir .= $name{0}.'/';
}
break;
}
if(!is_dir($file['savepath'].$dir)) {
mkdir($file['savepath'].$dir);
}
return $dir;
}

/**
+----------------------------------------------------------
* 檢查上傳的文件
+----------------------------------------------------------
* @access private
+----------------------------------------------------------
* @param array $file 文件信息
+----------------------------------------------------------
* @return boolean
+----------------------------------------------------------
*/
private function check($file) {
if($file['error']!== 0) {
//文件上傳失敗
//捕獲錯誤代碼
$this->error($file['error']);
return $this -> error;
}

//檢查文件Mime類型
if(!$this->checkType($file['type'])) {
$this->error = '上傳文件MIME類型不允許!';
return $this -> error;
}
//檢查文件類型
if(!$this->checkExt($file['extension'])) {
$this->error ='上傳文件類型不允許';
return $this -> error;
}
//文件上傳成功,進行自定義規則檢查
//檢查文件大小
if(!$this->checkSize($file['size'])) {
$this->error = '上傳文件大小超出限制!';
return $this -> error;
}

//檢查是否合法上傳
if(!$this->checkUpload($file['tmp_name'])) {
$this->error = '非法上傳文件!';
return $this -> error;
}
return true;
}

/**
+----------------------------------------------------------
* 檢查上傳的文件類型是否合法
+----------------------------------------------------------
* @access private
+----------------------------------------------------------
* @param string $type 數據
+----------------------------------------------------------
* @return boolean
+----------------------------------------------------------
*/
private function checkType($type)
{
if(!empty($this->allowTypes))
return in_array(strtolower($type),$this->allowTypes);
return true;
}

/**
+----------------------------------------------------------
* 檢查上傳的文件後綴是否合法
+----------------------------------------------------------
* @access private
+----------------------------------------------------------
* @param string $ext 後綴名
+----------------------------------------------------------
* @return boolean
+----------------------------------------------------------
*/
private function checkExt($ext)
{
if(!empty($this->allowExts))
return in_array(strtolower($ext),$this->allowExts,true);
return true;
}

/**
+----------------------------------------------------------
* 檢查文件大小是否合法
+----------------------------------------------------------
* @access private
+----------------------------------------------------------
* @param integer $size 數據
+----------------------------------------------------------
* @return boolean
+----------------------------------------------------------
*/
private function checkSize($size)
{
return !($size > $this->maxSize) || (-1 == $this->maxSize);
}

/**
+----------------------------------------------------------
* 檢查文件是否非法提交
+----------------------------------------------------------
* @access private
+----------------------------------------------------------
* @param string $filename 文件名
+----------------------------------------------------------
* @return boolean
+----------------------------------------------------------
*/
private function checkUpload($filename)
{
return is_uploaded_file($filename);
}

/**
+----------------------------------------------------------
* 取得上傳文件的後綴
+----------------------------------------------------------
* @access private
+----------------------------------------------------------
* @param string $filename 文件名
+----------------------------------------------------------
* @return boolean
+----------------------------------------------------------
*/
private function getExt($filename)
{
$pathinfo = pathinfo($filename);
return $pathinfo['extension'];
}

/**
+----------------------------------------------------------
* 取得上傳文件的信息
+----------------------------------------------------------
* @access public
+----------------------------------------------------------
* @return array
+----------------------------------------------------------
*/
public function getUploadFileInfo()
{
return $this->uploadFileInfo;
}

/**
+----------------------------------------------------------
* 取得最後一次錯誤信息
+----------------------------------------------------------
* @access public
+----------------------------------------------------------
* @return string
+----------------------------------------------------------
*/
public function getErrorMsg()
{
return $this->error;
}

}//類定義結束
?>

⑤ 高分求免費的,php+mysql的,在線表格管理源碼

開網店的話,下載個ECSHOP,不是簡單很多嗎。

⑥ 用PHP實現表單提交,把數據存貯在記事本里,高手指點下,最好有源碼,謝謝了

直接上代碼,復制運行即可:
<?php
$name=$_POST['username'];
$sex = $_POST['sex'];
$fp = fopen('count.txt',"w+");
$str = $name."\n".$sex;
fputs($fp,$str);
fclose($fp);

?>
<html>
<head></head>
<body>
<form method="post" name="form" action="study22.php">
<table>
<tr>
<td>用戶名:</td>
<td><input type="text" name="username"/></td>
</tr>
<tr>
<td>性別:</td>
<td><input type="text" name="sex" /></td>
</tr>
</table>
<input type="submit" name="submit" value="提交"/>
</form>
</body>
</html>

⑦ 如何查看php文件原碼,懸賞50分

php是內嵌html內的模塊.在伺服器端執行,而不是在工作站端執行.你看不到源碼.
不排除別有途徑可以看到源碼.

⑧ 求PHP高手給出一個在線排版源碼。謝謝。

--space-after-if --optimize-eol --space-after-switch --space-after-while --space-before-start-angle-bracket --space-after-end-angle-bracket --extra-padding-for-case-statement --glue-amperscore --change-shell-comment-to-double-slashes-comment --indent-with-tab --force-large-php-code-tag --force-true-false-null-contant-lowercase --comment-rendering-style PEAR --equal-align-position 50 --padding-char-count 1 "$(FilePath)"

⑨ 由網頁提交的表單提交寫入資料庫 PHP源代碼該怎麼寫

把下面的代碼保存為post.php

<?
$conn = mysql_connect("localhost","11111","22222");
$action = $_POST['action'];
if($action == 'send'){
$username = $_POST['username'];
$password = $_POST['password'];
mysql_select_db("333333",$conn);
$sql = "INSERT INTO player (username,password) VALUES ('$username','$password')";
$result = mysql_query($sql,$conn);
}
?>

<html>
<body>
<form method="post" action="post.php">
<input type="text" name="username">
<input type="text" name="password">
<input type="hidden" name="action" value="send">
<input type="submit" name="Submit" value="提交">
</form>
</body>
</html>

⑩ php表單提交

1 用JS提交表單的方法
首先通過JS判斷選擇的是哪個項目 然後 在條件里 提交到不同的頁面
2 建一個PHP頁面 判斷提交來的選項里是哪個項目
再通過GET方式將表單的內容傳到相應的頁面
3 可以將1.PHP和2.PHP 寫在一個文件里 然後判斷選項來選擇處理代碼

閱讀全文

與php在線表單源碼相關的資料

熱點內容
自己購買雲主伺服器推薦 瀏覽:419
個人所得稅java 瀏覽:761
多餘的伺服器滑道還有什麼用 瀏覽:189
pdf劈開合並 瀏覽:26
不能修改的pdf 瀏覽:750
同城公眾源碼 瀏覽:488
一個伺服器2個埠怎麼映射 瀏覽:297
java字元串ascii碼 瀏覽:78
台灣雲伺服器怎麼租伺服器 瀏覽:475
旅遊手機網站源碼 瀏覽:332
android關聯表 瀏覽:945
安卓導航無聲音怎麼維修 瀏覽:332
app怎麼裝視頻 瀏覽:430
安卓系統下的軟體怎麼移到桌面 瀏覽:96
windows拷貝到linux 瀏覽:772
mdr軟體解壓和別人不一樣 瀏覽:904
單片機串列通信有什麼好處 瀏覽:340
游戲開發程序員書籍 瀏覽:860
pdf中圖片修改 瀏覽:288
匯編編譯後 瀏覽:491