[PHP] 可唔可以幫下我呀?

可唔可以幫我寫一個簡單既php
顯示目錄內所有檔案及資料夾
再加多個分頁功能, 每頁顯示10個檔案或資料夾名

我睇左好多教你整分頁個d網, 個個都係用database既...
顯示哂所有檔案, 又會搞到hang喎...
所以想整個分頁

有冇人可以幫到我呀?
Thx!!

既然你話簡單PHP, 點解唔嘗試自己找出問題所在呢!

搵人幫你寫係學唔到嘢㗎.

Post 你寫D code睇吓點解會hang.

TOP

  1. $dir = "../test/"; //資料夾位置
  2. $a = scandir("$dir");
  3. $totalfile = count($a);

  4. for ( $i = 1 ; $i <= $totalfile ; $i ++) {
  5.         $filename = $a[$totalfile-$i];
  6.         $ext = strtolower(substr(strrchr($filename, "."), 1));
  7.         if($ext == "jpg" || $ext == "gif" || $ext == "png" || $ext == "jpeg" || $ext == "bmp"){
  8.         @list($width,$height,$type, $attr)=getimagesize($filename);
  9.         $MaxW= 320; //Set Max Width
  10.         $MaxH= 240;        //set Max Height
  11.         $tmp_w = $width;
  12.         $tmp_h = $height;               
  13.         if ($tmp_h > $MaxH) {
  14.         $tmp_h = $MaxH;       
  15.         $percent = ($height / $tmp_h);
  16.         $tmp_w = ($width / $percent);
  17.         }elseif ($tmp_w > $MaxW) {
  18.         $tmp_w = $MaxW;
  19.         $percent = ($width / $tmp_w);
  20.         $tmp_h = ($height / $percent);
  21.         }
  22. echo "<a href='$dir$filename' target=_blank border=0><img src='$dir$filename' width=$tmp_w height=$tmp_h border=0>"."</a>

  23. ";
  24. }elseif ($filename != "." && $filename != ".." && $filename != "Thumbs.db" && $ext !="php" ){
  25.         echo "<a href='$dir$filename' target=_blank>".$filename."</a>

  26. ";
  27. }
  28. }
複製代碼
我想做到分頁同埋可以

1.jpg 2.jpg 3.jpg
4.jpg 5.jpg 6.jpg
7.jpg 8.jpg 9.jpg
10.jpg

[FirstPage] [PrevPage] [X] [Next Page] [Last Page]

TOP

你諗住佢可以處理幾多RECORDS?
次次LOOP隨時部機既I/O勁重

TOP

原帖由 patrickit 於 2009-9-4 18:18 發表
你諗住佢可以處理幾多RECORDS?
次次LOOP隨時部機既I/O勁重

我都唔知可以處理幾多....
就係出幾千張圖先會hang嘛

其實我應該點做呢?

TOP

原帖由 poon120403 於 2009-9-4 18:26 發表

我都唔知可以處理幾多....
就係出幾千張圖先會hang嘛

其實我應該點做呢?

you can use another program (can use PHP as well) to populate the file information, such as file type, image size, thumbnail etc,  to database and then fetch the number of file records you want every time request received.  You can easily get the total number of records in the database to calculate the total number of pages and then setup the page selection bar.

Just update the database when there are changes in the directory, so that you don't need to scan the directory every time a request is received.  It will reduce overhead and minimize server load.

TOP

原帖由 [email protected] 於 2009-9-4 23:28 發表

you can use another program (can use PHP as well) to populate the file information, such as file type, image size, thumbnail etc,  to database and then fetch the number of file records you want every ...

即係最好用返database啦
再試下用database先...

TOP

原帖由 poon120403 於 2009-9-4 23:52 發表

即係最好用返database啦
再試下用database先...

I think it cannot be avoided to use database in most of the web applications

TOP

就算唔用DB,用一個text file index左個directory都快好多
講緊既係每次只係load一個file, much faster

TOP

原帖由 [email protected] 於 2009-9-4 23:28 發表

you can use another program (can use PHP as well) to populate the file information, such as file type, image size, thumbnail etc,  to database and then fetch the number of file records you want every ...


讀完一次淨file name用session variables儲住會唔會放唔哂?
其他料每個page要show幾多先loop幾多搵番出黎

[ 本帖最後由 dvd-rw 於 2009-9-5 01:29 編輯 ]

TOP