① php+mysql圖片的插入、顯示操作代碼
如果存圖片流,資料庫會非常龐大,建議還是存路徑,圖片放到統一的目錄下,方便管理
存就是insert 欄位用vchar的存相對路徑就可以了
讀就是查資料庫 然後放到數組里 、
顯示<img src='讀出來的變數'>就可以了
function uploadPhoto ($file) {
$this->result = false;
$this->error = false;
// -- save parameters
$this->_file = $file;
//get path
$this->createUploadDir();
$this->_destination=SystemProperties::$UPLOAD_ROOT_PATH['photo'];
//if (!is_null($allowed)) { $this->_allowed = $allowed; } else { $this->_allowed = array('jpg','jpeg','gif','png'); }
// -- check that FILE array is even set
if (isset($file) && is_array($file) && !$this->upload_error($file['error'])) {
// -- cool, now set some variables
$fileID=$this->_IDGenerator->getNextId('IMAGE');
$fileExt=$this->ext($file['name']);
$fileName =$fileID.'.'.$fileExt;
$this->createFileDir('image',$fileName);
$fileTmp = $file['tmp_name'];
//$fileSize = $file['size'];
//$fileType = $file['type'];
$fileError = $file['error'];
// -- update name
$this->_name = $this->_destination.$fileName;
// -- it's been uploaded with php
if (is_uploaded_file($fileTmp)) {
// -- where to put the file?
$filePath=$this->_fileUtil->getFilePath($fileName);
$output = $this->_destination.$filePath['filePath'];
//resize the img first
$isFileName_f=$this->resizeImage($this->_file,'f',$filePath['noExtFileName'].'_f'.$filePath['ext']);
//or resize the img like this,choosed type in ('a','b','c')
//$isFileName_b=$this->resizeImage($this->_file,'b',$filePath['noExtFileName'].'_b'.$filePath['ext']);
if($isFileName_a==true && $isFileName_b==true && $isFileName_c==true && $isFileName_d==true){
// -- just upload it
if (move_uploaded_file($fileTmp, $output)) {
chmod($output, 0644);
$this->result = basename($this->_name);
return $this->result;
} else {
$this->error("Could not move '$fileName' to '$this->_destination'");
}
}
} else {
$this->error("Possible file upload attack on '$fileName'");
}
} else {
$this->error("Possible file upload attack");
}
}
用php框架的,和純php寫不一樣,但是問題不大就是一個思路,沒有完全通用的代碼,前台加個上傳框,做個form傳到後台就不用寫了吧,傳過來的參數$file就是文件,也是個數組用$_FILE[]能看到,首先校驗後綴名或者前台js校驗,move_uploaded_file這句是最重要的一句,其他都是輔助准備參數而已,意思就是把傳上來的東西放到哪去,路徑加文件名 $output 這個參數就是你要保存到資料庫的值了
② thinkphp 配置路由
對的,寫在項目下面的config.php就好了。
③ iis php偽靜態怎麼設置
thinkphp :把以下代碼保存成web.config文件,放到網站根目錄內即可。
<?xml version="1.0" encoding="UTF-8"?><configuration>
<system.webServer>
<rewrite>
<rules>
<rule name="ThinkPHP_NiPaiYi" stopProcessing="true">
<match url="^(.*)$" ignoreCase="false" />
<conditions logicalGrouping="MatchAll">
<add input="{REQUEST_FILENAME}" matchType="IsDirectory" ignoreCase="false" negate="true" />
<add input="{REQUEST_FILENAME}" matchType="IsFile" ignoreCase="false" negate="true" />
</conditions>
<action type="Rewrite" url="index.php/{R:1}" appendQueryString="true" />
</rule>
</rules>
</rewrite>
</system.webServer></configuration>
④ thinkphp iis 如何去掉index.php
如果你的伺服器環境支持ISAPI_Rewrite的話,可以配置httpd.ini文件,添加下面的內容:
RewriteRule(.*)$/index.php?s=$1[I]
在IIS的高版本下面可以配置web.Config,在中間添加rewrite節點:
<rewrite>
<rules>
<rulename="OrgPage"stopProcessing="true">
<matchurl="^(.*)$"/>
<conditionslogicalGrouping="MatchAll">
<addinput="{HTTP_HOST}"pattern="^(.*)$"/>
<addinput="{REQUEST_FILENAME}"matchType="IsFile"negate="true"/>
<addinput="{REQUEST_FILENAME}"matchType="IsDirectory"negate="true"/>
</conditions>
<actiontype="Rewrite"url="index.php/{R:1}"/>
</rule>
</rules>
</rewrite>
參考文檔:http://www.kancloud.cn/manual/thinkphp/1866
⑤ thinkphp5 怎麼把默認的index去掉
1在Apache根目錄conf文件夾下的httpd.conf配置文件中載入mod_rewrite.so模塊;
#LoadMole rewrite_mole moles/mod_rewrite.so把前面的警號去掉
2
AllowOverride None 將None改為 All
在APACHE裡面去配置 (注意其他地方的AllowOverride也統統設置為ALL)
即:AllowOverride none 改 AllowOverride ALL
保存httpd.conf,重啟Apache伺服器;
3 確保URL_MODEL設置為2,在項目的配置文件里寫 'URL_MODEL' => '2',
4
.htaccess文件必須放到跟目錄下,在文件裡面添加:
<IfMole mod_rewrite.c>
Options +FollowSymlinks
RewriteEngine onRewriteCond %{REQUEST_FILENAME} !-dRewriteCond %{REQUEST_FILENAME} !-fRewriteRule ^(.*)$ index.php/$1 [QSA,PT,L]</IfMole>
⑥ 創建應用目錄後入口文件index.php應如何改寫
可以通過URL重寫隱藏應用的入口文件index.php
[ Apache ]
1. httpd.conf配置文件中載入了mod_rewrite.so模塊
2. AllowOverride None 將None改為 All
3. 把下面的內容保存為.htaccess文件放到應用入口文件的同級目錄下
<IfMole mod_rewrite.c>RewriteEngine onRewriteCond %{REQUEST_FILENAME} !-dRewriteCond %{REQUEST_FILENAME} !-fRewriteRule ^(.*)$ index.php/$1 [QSA,PT,L]</IfMole>
[ IIS ]
如果你的伺服器環境支持ISAPI_Rewrite的話,可以配置httpd.ini文件,添加下面的內容:
RewriteRule (.*)$ /index\.php\?s=$1 [I]
在IIS的高版本下面可以配置web.Config,在中間添加rewrite節點:
<rewrite><rules><rule name="OrgPage" stopProcessing="true"><match url="^(.*)$" /><conditions logicalGrouping="MatchAll"><add input="{HTTP_HOST}" pattern="^(.*)$" /><add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" /><add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" /></conditions><action type="Rewrite" url="index.php/{R:1}" /></rule></rules></rewrite>
[ Nginx ]
在Nginx低版本中,是不支持PATHINFO的,但是可以通過在Nginx.conf中配置轉發規則實現:
location / { // …..省略部分代碼 if (!-e $request_filename) { rewrite ^(.*)$ /index.php?s=$1 last; break; }}
如果你的ThinkPHP安裝在二級目錄,Nginx的偽靜態方法設置如下,其中youdomain是所在的目錄名稱。
location /youdomain/ { if (!-e $request_filename){ rewrite ^/youdomain/(.*)$ /youdomain/index.php?s=$1 last; }}
——轉自ThinkPHP3.2.3開發手冊
⑦ 請問php5之後可以用純面向對象來開發嗎
面向對象的開發易於開發和維護以及後期迭代
面向過程其實也是可以的
⑧ 請教各位大神,iis環境下配置thinkphp,頁面錯誤
IIS環境
如果你的伺服器環境支持ISAPI_Rewrite的話,可以配置httpd.ini文件,添加下面的內容:
RewriteRule(.*)$/index.php?s=$1[I]
<rewrite>
<rules>
<rulename="OrgPage"stopProcessing="true">
<matchurl="^(.*)$"/>
<conditionslogicalGrouping="MatchAll">
<addinput="{HTTP_HOST}"pattern="^(.*)$"/>
<addinput="{REQUEST_FILENAME}"matchType="IsFile"negate="true"/>
<addinput="{REQUEST_FILENAME}"matchType="IsDirectory"negate="true"/>
</conditions>
<actiontype="Rewrite"url="index.php/{R:1}"/>
</rule>
</rules>
</rewrite>
⑨ 如何用php讀取指定文件夾里所有文件並做成鏈接
<?php
//設定報錯等級,如果是開源程序插件不需要設定
error_reporting(E_ERROR|E_PARSE);
//定義欲讀取的目錄路徑,方便演示,本程序讀取的是當前文件所在目錄
$path='.';
//獲取文件列表數組
$files=ReadFolder($path);
//處理文件列表數組
foreach($filesas$value){
//顯示文件鏈接
echo'<ahref="'.$value.'">'.$value.'</a>';
//為方便查看,輸出一個<br/>換行符
echo'<br/>';
}
/*定義自定義函數*/
/**
*獲取文件列表
*
*@paramstring $dir 欲讀取的目錄路徑
*@paramboolean$mode0:讀取全部;1:僅讀取文件;2:僅讀取目錄
*@returnarray
*/
functionReadFolder($dir,$mode=0){
//如果打開目錄句柄失敗,則輸出空數組
if(!$handle=@opendir($dir))returnarray();
//定義文件列表數組
$files=array();
//遍歷目錄句柄中的條目
while(false!==($file=@readdir($handle))){
//跳過本目錄以及上級目錄
if('.'===$file||'..'===$file)continue;
//是否僅讀取目錄
if($mode===2){
if(isDir($dir.'/'.$file))$files[]=$file;
//是否僅讀取文件
}elseif($mode===1){
if(isFile($dir.'/'.$file))$files[]=$file;
//讀取全部
}else{
$files[]=$file;
}
}
//關閉打開的目錄句柄
@closedir($handle);
//輸出文件列表數組
return$files;
}
/**
*判斷輸入是否為目錄
*
*@paramstring$dir
*@returnboolean
*/
functionisDir($dir){
return$dir?is_dir($dir):false;
}
/**
*判斷輸入是否為文件
*
*@paramstring$file
*@returnboolean
*/
functionisFile($file){
return$file?is_file($file):false;
}
?>
⑩ thinkphp框架開發後台文件管理功能求救
在控制器中 import("ORG.Io.Dir");構建完路徑後, $dir = new Dir($path);
$list = $dir->_values;在模板用volist 進行循環輸出數組不成功,進行mp($list)為NULL值, 更換為$list = $dir->getIterator();後也不成功,但是進行mp的時候數組數據已經建立,問下這樣的數組如何在模板循環輸出?? mp數據為以下代碼:
object(ArrayObject)#4 (1) { ["storage":"ArrayObject":private] => array(29) { [0] => array(18) { ["filename"] => string(3) "bbb" ["pathname"] => string(15) "F:\wamp\www\bbb" ["owner"] => int(0) ["perms"] => int(16895) ["inode"] => int(0) ["group"] => int(0) ["path"] => string(11) "F:/wamp/www" ["atime"] => int(1313063512) ["ctime"] => int(1312255725) ["size"] => int(0) ["type"] => string(3) "dir" ["ext"] => string(0) "" ["mtime"] => int(1313063512) ["isDir"] => bool(true) ["isFile"] => bool(false) ["isLink"] => bool(false) ["isReadable"] => bool(true) ["isWritable"] => bool(true) } [1] => array(18) { ["filename"] => string(8) "�1�7�1�7�0�5�0�0�1�7�1�7" ["pathname"] => string(20) "F:\wamp\www\�1�7�1�7�0�5�0�0�1�7�1�7" ["owner"] => int(0) ["perms"] => int(16895) ["inode"] => int(0) ["group"] => int(0) ["path"] => string(11) "F:/wamp/www"