導航:首頁 > 編程語言 > php遠程文件夾

php遠程文件夾

發布時間:2022-08-15 17:29:31

『壹』 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程序自動讀取遠程文件並更新到本地,每天一次,如何做

windows:
准備:
1.將 php.exe 的路徑加入 windows 的環境變數
2.編寫文件:
D:\fileGeter.php
<?php
$filelist = Array(
"http://**********/a.txt",
"http://**********/b.txt",
);

$saveas="D:\\" ;
$endl = ".txt"

function getfile(){
foreach( $filelist as $k => $file )
file_put_contents( $saveas . $k . $endl , file_get_contents( $file ) ) ;
}
getfile();
?>
3.執行cmd命令
at 11:20 /every:1,2,3,4,5,6,7 "php D:\fileGeter.php"

linux 更方便

直接把此文件包含進 你要寫的程序里就OK了,

fileGeter.php:
<?php
...
...
$saveas = "./";
...
..

?>
index.php:
<?php
require_once("fileGeter.php");
//and so on .....
.....
....
....
?>

『叄』 php獲取遠程文件的大小

本文實例講述了php獲取遠程文件大小的方法,分享給大家供大家參考。具體實現方法如下:
/*
**功能:獲取遠程文件的大小,返回值的單位是:位元組
*/
function
get_fileSize($url){
if(!isset($url)||trim($url)==''){
return
'';
}
ob_start();
$ch=curl_init($url);
curl_setopt($ch,CURLOPT_HEADER,1);
curl_setopt($ch,CURLOPT_NOBODY,1);
$okay=curl_exec($ch);
curl_close($ch);
$head=ob_get_contents();
ob_end_clean();
$regex='/Content-Length:\s([0-9].+?)\s/';
$count=preg_match($regex,$head,$matches);
return
isset($matches[1])&&is_numeric($matches[1])?$matches[1]:'';
}
希望本文所述對大家的php程序設計有所幫助,大家能夠喜歡小便的文章,大家共同進步。

『肆』 php自動下載遠程文件問題

..com/index.php?down=1006
把down傳給index文件
在index文件中,做個判斷即可
index.php
<?php
if($_GET[dwon])
{
$filename=$_GET[dwon];
switch($filename){
case 1006:
echo "http://www..com/wc/filename.rar";break;
case 其他值:
echo "其他文件地址";break;
}
}
?>

『伍』 php window遠程文件訪問

php沒有這個功能

『陸』 php保存遠程文件到文件夾

命令需要有個前提,並不是能隨便就打開區域網中的電腦。你需要有個許可權,如果對方的電腦設置了密碼你是根本進不了的,最好的方法就是給對方的電腦安裝一個遠程軟體,你登錄就可以了。

『柒』 php怎樣遍歷遠程文件夾下的文件

window是用的GB2312的編碼,你的php文件應該用的是UTF-8,所以正如你寫的那樣,先要轉換編碼$dir=iconv("utf-8","gb2312",$dir);
但你別忘了,你用的是UTF-8的編碼,所以你第六行寫錯了,把GB2312轉換為UTF-8搞倒了吧
123456789101112131415<?phpfunction refresh($dir){ $dir=iconv("utf-8","gb2312",$dir); if ($headle=opendir($dir)){ while ($file=readdir($headle)){ $file=iconv("gb2312","utf-8",$file); if ($file!='.' && $file!='..'){ echo "文件".$file."在文件夾".$dir."下<br />"; } } closedir($headle); }}refresh("D:/AppServ/www/test");?>

『捌』 php include 能包含遠程文件嗎

可以,但是需要修改配置程序。具體如下:

最好檢查一下php.ini中的配置選項allow_url_include,如果為on則可以包含,否則不能包含
; Whether to allow include/require to open URLs (like http:// or ftp://) as files.
allow_url_include = Off

做個簡單的測試,此時allow_url_include的值為Off
測試前配置一下hosts文件,這樣可以在一台電腦上面進行模擬測試
192.168.1.101 www.test1.com
192.168.1.102 www.test2.com

path.php文件內容為:
<?php
echo "This is file path.php<br />\n";
include("http://www.test2.com/research/path/path.php");
?>

path1.php文件內容為:
<?php
echo "This is file path1.php in root directory\n";
?>
執行http://www.test1.com/research/path/path.php,輸出如下
This is file path.php

Warning: include() [function.include]: URL file-access is disabled in the server configuration in E:\myphp\research\path\path.php on line 3

Warning: include(http://www.test2.com/research/path/path.php) [function.include]: failed to open stream: no suitable wrapper could be found in E:\myphp\research\path\path.php on line 3

Warning: include() [function.include]: Failed opening 'http://www.test2.com/research/path/path.php' for inclusion (include_path='.;C:\php5\pear') in E:\myphp\research\path\path.php on line 3

將php.ini中的allow_url_include改為On,重新啟動web伺服器,再次執行http://www.test1.com/research/path/path.php,輸出如下:
This is file path.php
This is file path1.php in root directory
將allow_url_include設為On以後,就可以包含遠程文件了,並且包含的是遠程文件執行的結果。

閱讀全文

與php遠程文件夾相關的資料

熱點內容
做賬為什麼要用加密狗 瀏覽:583
考研群體怎麼解壓 瀏覽:156
linux修改命令提示符 瀏覽:224
圓圈裡面k圖標是什麼app 瀏覽:59
pdf加空白頁 瀏覽:945
linux伺服器如何看網卡狀態 瀏覽:316
解壓新奇特視頻 瀏覽:704
圖書信息管理系統java 瀏覽:551
各種直線命令詳解 瀏覽:861
程序員淚奔 瀏覽:145
素材怎麼上傳到伺服器 瀏覽:515
android百度離線地圖開發 瀏覽:189
web可視化編程軟體 瀏覽:292
java筆試編程題 瀏覽:745
win11什麼時候可以裝安卓 瀏覽:564
java不寫this 瀏覽:1001
雲點播電影網php源碼 瀏覽:97
pythonclass使用方法 瀏覽:226
移動加密軟體去哪下載 瀏覽:294
php彈出alert 瀏覽:209