2014-06-25 51 views
0

上使用PHP函數我寫一個PHP腳本和HostGator的服務器上運行它,它給這個錯誤:無法HostGator的服務器

Warning: file_get_contents( http://affiliates.kissmyads.com/stats/lead_report.json?api_key=AFFRd3xa8hRB3xOj7KsPnmQhlFYgNE&start_date=2014-06-24&end_date=2014-06-24) [function.file-get-contents]: failed to open stream: No such file or directory in www/barpy-money.in/app/kissmyads.php on line 10

這是無法加載函數文件得到-內容()。我直接在我的程序中使用這個函數。當我在joomla文章中運行此代碼時,它工作正常,但在服務器上它給出了錯誤。誰能告訴我爲什麼會發生這種情況?

這是我的代碼:

<?php 

require_once 'include/DB_Connect.php'; 
    // connecting to database 
    $db = new DB_Connect(); 
    $db->connect(); 

$url = ' http://affiliates.kissmyads.com/stats/lead_report.json?api_key=my_api_key&start_date=2014-06-24&end_date=2014-06-24'; 

$result = file_get_contents($url); // line number 10 

echo '<pre>'; 
print_r(json_decode($result)); 
echo '</pre>'; ?> 
+1

網址通常不以空格字符開頭。 – mario

+0

措辭不佳的標題。 –

+0

非常感謝我的問題解決! – Barpy

回答

1

用於該功能php.net文檔具有在底部的尖端:

提示 如果fopen封裝已被啓用的URL可以被用作具有這種功能的文件名。有關如何指定文件名的更多詳細信息,請參閱fopen()。

爲了做到這一點,你需要編輯你的php.ini文件。每hostgators說明:

allow_url_fopen選項,如何啓用

這可以通過你的php.ini文件中加入以下行來完成:

了allow_url_fopen =在 php.ini文件中,您聲明更改您的PHP設置。您可以編輯現有的php.ini,或者在任何子目錄中創建一個新的文本文件並將其命名爲php.ini。

http://support.hostgator.com/articles/specialized-help/technical/allow_url_fopen-how-to-enable

另外你的HTTP前,先在$ url變量的空間。

0

將檢查在你的php.ini啓用

allow_url_fopen = on 

嘗試檢查phpinfo()

或可能是網址不存在給你在file_get_contents()也不要添加url中的空格,你需要設置像: -

$url = "http://affiliates.kissmyads.com/stats/lead_report.json?api_key=my_api_key&start_date=2014-06-24&end_date=2014-06-24"; 
$result = file_get_contents($url);