2015-09-27 61 views
2

我想使用下面的代碼找到WAV文件的持續時間。fopen說未能打開流:未定義的錯誤:0,但文件存在通過

if (!file_exists($location_wmv.$name_wmv)) { 
      echo "<BR> File Does not Exist<BR>"; 
      } else { 
       echo "<BR> File Exist<BR>"; 
      } 
     $file = $location_wmv.$name_wmv; 
     $fp = fopen($file, ‘r’); 
     $size_in_bytes = filesize($file); 
     fseek($fp, 20); 
     $rawheader = fread($fp, 16); 
     $header = unpack(‘vtype/vchannels/Vsamplerate/Vbytespersec/valignment/vbits’, 
     $rawheader); 
     $sec = ceil($size_in_bytes/$header['bytespersec']); 
     $duration_wmv = $sec; 
     echo "<BR> Raw Suration.". $duration_wmv . "<BR>"; 
     $duration_wmv = gmdate("H:i:s", $demo_song_duration_sec); 
     echo "<BR>WAV Duration".$duration_wmv; 

這裏的file_exists函數說這個文件存在。但是fopen說failed to open stream: Undefined error: 0 該文件實際上存在於該文件夾中。但是我仍然得到這個錯誤。

+1

好了,大概的過程中沒有權限打開該文件。檢查文件系統級別的文件權限。請記住,http服務器通常在單獨的帳戶下運行。 – arkascha

+0

@arkascha - 在這種情況下file_exists函數也會返回false,否? –

+0

如果您有目錄的讀取權限,則不是。 – arkascha

回答

0

此:

$fp = fopen($file, ‘r’); 

看起來前途未卜。那些反引號? 也許嘗試:

$fp = fopen($file, 'r'); 

(簡單引號)

相關問題