2015-06-22 102 views
3

沒有這樣的文件或目錄,我下面的教程從Android上傳圖片到服務器和我使用的是服務器端的PHP,這是代碼:的fopen(uploadedimages /):未能打開流:在

<?php 
    error_get_last(); 
    chmod("./uploadedimages/", 777); 
    // Get image string posted from Android App 
    $base=$_REQUEST['image']; 
    // Get file name posted from Android App 
    $filename = $_REQUEST['filename']; 
    // Decode Image 
    $binary=base64_decode($base); 
    header('Content-Type: bitmap; charset=utf-8'); 
    // Images will be saved under 'www/imgupload/uplodedimages' folder 
    $file = fopen('uploadedimages/'.$filename, 'wb'); 
    // Create File 
    fwrite($file, $binary); 
    fclose($file); 
    echo 'Image upload complete, Please check your php file directory'; 
?> 

當我嘗試運行,它讓我看到以下錯誤:

的fopen(uploadedimages /):未能打開流:沒有這樣的文件或目錄 在...

fwrite()期望參數1到b Ë資源,在... FCLOSE定的boolean()預計參數1是資源,鑑於布爾...

我很新的PHP所以請幫助我(我發現一些答案從互聯網,但它並沒有爲我工作)

+0

一個經常運行到這個錯誤,並迅速解決它,請按照下列步驟操作:http://stackoverflow.com/a/36577021/2873507 –

回答

3

你需要給文件的完整路徑fopen()

$file = fopen($_SERVER['DOCUMENT_ROOT'].'/uploadedimages/'.$filename, 'wb'); 

另外,還要確保你有正確的權限創建在一個文件裏服務器。

而且,由於沒有在第一時間得到所創建的文件,你得到的錯誤,當你試圖使用fwrite()fclose()

+0

其實,我得到了同樣的錯誤。我創建了文件uploadedimages。它存在。我如何確保我擁有在我的服務器中創建文件的正確權限。 – Alex41

+0

哪些是您使用?Linux或Windows服務器? – Abhinav

+0

我在Windows 8中使用集成在wamp中的apache服務器 – Alex41

0

failed to open stream錯誤時,PHP不能找到你所指定的路徑發生。而且還認爲你沒有指定文件擴展名,以便使用類似fopen('uploadedimages/'.$filename.'.png', 'w+')。該擴展可能是您的首選。

+0

現在有一個此故障排除清單頻繁的錯誤在這裏:stackoverflow.com/a/36577021/2873507 –