2011-03-10 48 views
0

我有下面的PHP代碼:包容 - 不同的結果比直接鏈接

<html> 
    <body> 
    <?php 
    $_GET = Array('filename' => 'scores/score.sco&scoresize=10&action=VIEW&viewtype=HTML'); // add the others here too 
    include('scores.php'); 
    ?> 
    </body> 
</html> 

有了這個代碼,我想包括此http://apps.facebook.com/krajecr/scores.php?filename=scores/score.sco&scoresize=10&action=VIEW&viewtype=HTML 直接鏈接的作品,但你可以看到從結果包括在這裏:http://apps.facebook.com/krajecr/pokus.php - error: Warning: fclose(): supplied argument is not a valid stream resource in /3w/webz.cz/p/programming/facebook/scores.php on line 9

你能幫我解決這個問題嗎?

scores.php可以在這裏找到http://www.flashkit.com/tutorials/Games/High-sco-Glen_Rho-657/index.php()

這裏是第10行:

<?php 

    $winscore = (int)$winscore; 

    // Create a Blank File if it doesn't already exist 
    if (!file_exists($filename)) 
    { 
     $file=fopen($filename, "w"); 
     fclose ($file); 
    } 
+0

什麼是第9行? – 2011-03-10 01:26:39

+0

'scores.php'的內容是什麼?也請在問題中發佈錯誤,而不是依賴可能會改變/消失的外部網站。 – 2011-03-10 01:31:31

+0

fclose($ file); – Tom83B 2011-03-10 01:31:43

回答

0

錯誤說,你要的東西做fclose,這不是一個流資源。

假設你從fopen$file,這裏唯一的情況是,fopen失敗使$filenot a stream resource,但FALSE。例如,如果您的網絡服務器正在運行的用戶沒有創建文件的權限,則可能會失敗。

將錯誤檢查添加到您的函數調用中。

我無法解釋爲什麼當PHP通過Web執行包含請求時,這會有所不同。

編輯

$_GET = Array('filename' => 'scores/score.sco&scoresize=10&action=VIEW&viewtype=HTML'); // add the others here too 

應該

$_GET = Array(
    'filename' => 'scores/score.sco', 
    'scoresize' => '10', 
    'action' => 'VIEW', 
    'viewtype' => 'HTML' 
); 

退出試圖使用HTTP查詢字符串語法絕對到處;這不是世界的運作方式!

我還注意到「scores.php」似乎從來沒有定義$filename是什麼。難怪文件創建失敗:你永遠不會給它一個有效的文件名來創建!檢查fopen —的返回值,因爲您總是應該—會顯示此錯誤。您可能要寫$_GET['filename']

+0

該文件存在,如果你的分數/ score.sco – Tom83B 2011-03-10 01:41:44

+0

@ Tom83B:看我的編輯。 – 2011-03-10 01:45:02

+0

好的,謝謝。我將所有$文件名改爲'scores/score.sco',現在有效。 – Tom83B 2011-03-10 15:44:27