導航:首頁 > 編程語言 > php判斷網路文件是否存在

php判斷網路文件是否存在

發布時間:2022-05-20 22:34:01

『壹』 php判斷遠程文件是否存在

功能:判斷遠程文件是否存在 參數: $url_file -遠程文件URL 返回:存在返回true,不存在或者其他原因返回false*/function remote_file_exists($url_file){//檢測輸入$url_file = trim($url_file); if (empty($url_file)) { return false; } $url_arr = parse_url($url_file); if (!is_array($url_arr) || empty($url_arr)){return false; } //獲取請求數據 $host = $url_arr['host']; $path = $url_arr['path'] ."?".$url_arr['query']; $port = isset($url_arr['port']) ?$url_arr['port'] : "80"; //連接伺服器 $fp = fsockopen($host, $port, $err_no, $err_str,30); if (!$fp){ return false; } //構造請求協議 $request_str = "GET ".$path."HTTP/1.1\r\n"; $request_str .= "Host:".$host."\r\n"; $request_str .= "Connection:Close\r\n\r\n";//發送請求fwrite($fp,$request_str); $first_header = fgets($fp, 1024); fclose($fp); //判斷文件是否存在

『貳』 php判斷刪掉指定文件是否存在,如果不存在者跳轉到指定網站怎麼弄

$file='file.txt';
$url='';

if(is_file($file)){
if(unlink($file)){
echo'DeleteSuccess';
}else{
echo'DeleteFail';
}
}else{
//文件不存在跳轉
echo'FileNotFound';
sleep(3);
header("Location:$url");
}

『叄』 php file_exists文件在,但是用if判斷怎麼顯示不存在啊 大家幫我看看錯在什麼地方,

現在你用amp,文件路徑用
$this->file="d:\\amp/apache/htdocs/qinghaiyan/qinghaiyan/json/renshu.json";
if(!file_exists($this->file)) {....}

在真正的server用$this->file="http://qinghaiyan.com/....

『肆』 php如何判斷文件是否存在,包括本地和遠程文件

當檢查的文件是本地時用php自帶的file_exists檢查就行了,而此函數只能檢查本地的函數是否存在, 所以如果要檢查遠程的文件是否存在只能用其它的方法了。 如果所伺服器中php的配置開啟了「allow_url_fopen = On」,即允許遠端訪問,那麼也很簡單,其實這個是php.ini中默認開啟的, 用fopen函數判斷就行了,能打開說明存在 如果allow_url_fopen = Off那麼可以用socket通訊來解決 下面寫的一個通用函數my_file_exists來檢查文件是否存在 function my_file_exists($file){if(preg_match('/^http:\/\//',$file)){//遠程文件if(ini_get('allow_url_fopen')){ if(@fopen($file,'r')) return true;}else{$parseurl=parse_url($file); $host=$parseurl['host']; $path=$parseurl['path']; $fp=fsockopen($host,80, $errno, $errstr, 10); if(!$fp)return false; fputs($fp,GET {$path} HTTP/1.1 \r\nhost:{$host}\r\n\r\n); 現在就可以調用此函數來檢查文件的存在性,而不用去考慮是遠程還是本地文件,或者是否禁用了allow_url_open

『伍』 PHP能不能判斷遠端HTTP伺服器上的文件是否存在 - 技術問答

file_exists(PHP 3, PHP 4, PHP 5)file_exists -- 檢查文件或目錄是否存在說明bool file_exists ( string filename )如果由 filename 指定的文件或目錄存在則返回 TRUE,否則返回 FALSE。 在 Windows 中要用 //computername/share/filename 或者 \\\\computername\\share\\filename 來檢查網路中的共享文件。

『陸』 php如何找到類的地址,判斷類是否存在,訪問,實例化,判斷某個方法是否存在,釋放該類

>我是在一個.php 判斷另一個.php 中的類,直接用class_exists 會出錯
在 在一個.php 中 include(另一個.php) 再用 class_exists

『柒』 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對目錄進行操作時,先用哪個函數對操作目錄進行是否存在的判斷

file_exists — 檢查文件或目錄是否存在
說明
bool file_exists ( string $filename )
檢查文件或目錄是否存在。
參數

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

返回值
如果由 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開發幫助文檔

『玖』 為什麼區域網中訪問主機apache根目錄下確實存在的php文件,提示Not Found,而訪問主機虛擬目錄下正常

原因:DNS伺服器地址的問題。

1.使用360瀏覽器的用戶可以點擊頂部的「工具」/「選項」,選擇「刪除在線痕跡」;

『拾』 php上傳文件前判斷是否存在該文件就刪除

使用文件名來確定啊,if(isset(文件名))然後使用php的文件處理函數unlink來刪除

閱讀全文

與php判斷網路文件是否存在相關的資料

熱點內容
資料庫查詢系統源碼 瀏覽:617
php5314 瀏覽:358
完美國際安裝到哪個文件夾 瀏覽:669
什麼app可以掃一掃做題 瀏覽:540
程序員編碼論壇 瀏覽:924
淘點是什麼app 瀏覽:660
中國高等植物pdf 瀏覽:454
51單片機時間 瀏覽:182
後台如何獲取伺服器ip 瀏覽:267
單片機流水燈程序c語言 瀏覽:236
程序員第二職業掙錢 瀏覽:240
運行里怎麼輸入伺服器路徑 瀏覽:843
pythonstepwise 瀏覽:512
劉一男詞彙速記指南pdf 瀏覽:66
php認證級別 瀏覽:371
方舟編譯啥時候推送 瀏覽:1012
php手機驗證碼生成 瀏覽:677
哲學思維pdf 瀏覽:17
凌達壓縮機有限公司招聘 瀏覽:535
weblogic命令部署 瀏覽:39