導航:首頁 > 版本升級 > php判斷本地文件是否存在

php判斷本地文件是否存在

發布時間:2023-04-26 02:20:57

① php判斷文件夾或文件是否存在,及不存在時如何創建

如果文抄件夾不存在直接襲創建:

$folder='test';
is_dir($folder)ORmkdir($folder,0777,true);

文件不存在直接打開文件就創建了

$file='index.php';
is_file($file)ORfclose(fopen($file,'w'));

② php 檢測文件是否存在的幾種方式

一、 file_exists();

二、is_file();

$file='test';

file_exists($file)ORexit('該目錄不存在');

is_file($file)ORexit('該目錄不存在');

file_exists 既可以用來檢查文件夾,也可以用來檢查文件

is_file 只能用來檢查文件

③ php檢測文件夾下是否還有文件

php判斷文件還是文件夾主要通過is_file跟is_dir函數判斷,下面分別講解:
is_file()函數
is_file()函數 用來判斷是否為文件,返回結果為true或者false
舉例:
$ifile="c:/test";
$result=is_file($ifile);
echo $result;
輸出:false
is_dir()函數
is_dir()函數用來判斷是否為目錄,返回結果為true或者false
舉例:
$ifile="c:/test";
$result=is_file($ifile);
echo $result;
輸出:true

④ php判斷文件夾是否存在不存在則創建

//直接這樣即可:
$dir='./test/test';
is_dir($dir)ORmkdir($dir,0777,true);//如果文件夾不存在,將以遞歸方式創建該文件夾

⑤ php中如何判斷一個目錄有沒有文件

/**
*判斷是否為空目錄
*@param$pathstring指定的路徑
*@returnbool非空目錄和非目錄均返回false
*/
functionis_empty_dir($path){
if(!is_dir($path)){
returnfalse;
}

$dir=opendir($path);
while(false!==($file=readdir($dir))){
if(!in_array($file,['.','..'])){
closedir($dir);
returnfalse;
}
}

closedir($dir);
returntrue;
}

⑥ php判斷目錄是否存在

file_exists — 檢查文件或目錄是否存在

說明

bool file_exists ( string $filename )

檢查文件或目錄是否存在。

參數

filename

文件或目錄的路徑。

在 Windows 中要用 //computername/share/filename 或者 \computernamesharefilename 來檢查網路中的共享文件。


返回值

如果由 filename 指定的文件或目錄存在則返回 TRUE,否則返回 FALSE。

Note:

This function will return FALSE for symlinks pointing to non-existing files.


Warning

如果因為安全模式的限制而導致不能訪問文件的話,該函數會返回 FALSE。然而,可以使用 include 來包含,如果文件在 safe_mode_include_dir 所指定的目錄里。

Note:

The check is done using the real UID/GID instead of the effective one.


Note: 因為 PHP 的整數類型是有符號整型而且很多平台使用32位整型, 對2GB以上的文件,一些文件系統函數可能返回無法預期的結果 。

範例

Example #1 測試一個文件是否存在

<?php
$filename='/path/to/foo.txt';

if(file_exists($filename)){
echo"文件$filename存在";
}else{
echo"文件$filename不存在";
}
?>
//以上內容來自官方PHP開發幫助文檔


⑦ php如何實現判斷文件是否存在後跳轉

file_exists
(PHP 3, PHP 4 )

file_exists -- 檢查文件或目錄是否存在
說明
bool file_exists ( string filename)

如果由 filename 指定的文件或目錄存在則返回回 TRUE,否則返回 FALSE。

在 Windows 中要用 //computername/share/filename 或者 \\computername\share\filename 來檢查網路中答的共享文件。

例子 1. 測試一個文件是否存在

<?php
$filename = '/path/to/foo.txt';

if (file_exists($filename)) {
print "The file $filename exists";
} else {
print "The file $filename does not exist";
}
?>

閱讀全文

與php判斷本地文件是否存在相關的資料

熱點內容
公文中文件式格式是 瀏覽:858
陰陽師文件夾叫什麼 瀏覽:775
php站長工具源碼 瀏覽:440
vs沒有C語言頭文件 瀏覽:489
免費客戶資料庫軟體 瀏覽:287
公文有哪些文件 瀏覽:325
能群積分pk的qq版本 瀏覽:362
處對象徵婚app邀請碼哪裡有 瀏覽:473
js綁定checkbox 瀏覽:348
蘋果6換殼原裝多少錢 瀏覽:491
pythonmysql新資料庫 瀏覽:360
qq自定義 瀏覽:878
360如何查看源文件 瀏覽:494
聯通3g網路制式有哪些 瀏覽:916
qq游戲風雲再起積分 瀏覽:263
RosettaStone安卓語言包下載 瀏覽:376
jsp嵌入html代碼嗎 瀏覽:536
IJ是編譯哪個編程語言的 瀏覽:779
iqc掃碼標簽用什麼app 瀏覽:164
微信支付嵌入式模塊 瀏覽:876

友情鏈接