簡體   English   中英

我可以使用這句話嗎?

[英]Can i use this statement?

<?php
$file = 'example.txt';
$newfile = 'example.txt.bak';

if (!copy($file, $newfile)) {
    echo "failed to copy $file...\n";
}
?>

現在,我可以使用"http://engine.searchr.us/web-search.phtml?search=TEST+SEARCH"代替example.txt嗎?

可能嗎 ?

是的,只要您在PHP配置中啟用了allow_url_fopen,就可以。

對的,這是可能的。 如手冊所述:

如果已啟用“ fopen包裝器”,則源和dest現在都可以是URL。 有關更多詳細信息,請參見fopen()。

您可以使用PHP讀取遠程文件

$contents = '';
$file = fopen ("http://www.example.com/", "r");
if (!$file) {
    echo "<p>Unable to open remote file.\n";
    exit;
}
while (!feof ($file)) {
    $line = fgets ($file, 1024);
    $contents .= $line;
}
fclose($file);

echo $contents;

資源

http://php.net/manual/en/features.remote-files.php

正如EmilVikström所說,您必須啟用allow_url_fopen指令。 文件還指出,該指令只能設置成php.ini文件。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM