2013-04-20 182 views
0

我得到一個錯誤,我無法弄清楚,我正在做的是我有一個字符串或一堆網址,我把它們放入一個數組,然後循環數組並調整和上傳圖像,但我得到這個錯誤。任何幫助將非常感謝!PHP獲取文件內容

錯誤

file_get_contents(http://a513.phobos.apple.com/us/r1000/094/Purple/v4/d4/e4/02/d4e402a3-a485-4d4c-cf9b-90b0af391626/mzl.wbbwbbab.png) 
[function.file-get-contents]: failed to open stream: HTTP request failed! 
HTTP/1.0 400 Bad Request in "My File" on line 53 

PHP

include("picture-resize.php"); 

    $image = $_POST['thumbnail']; 
    $slug = $_POST['slug']; 
    $images = $_POST['screenshots']; 
    $list = explode(",", $images);  
    $listlength = count($list); 

    $i = 0; 

    $image = $_POST['thumbnail']; 

    $path = parse_url($image, PHP_URL_PATH); 

    $filename = $slug.'-'.$i; 

    $extension = pathinfo($path, PATHINFO_EXTENSION); 

    $file = $filename.'.'.$extension; 

    file_put_contents('../tmp/' . $file, file_get_contents($image)); 

    $picture = new pic_resize(); 

    $picture->load('../tmp/'.$file); 

    $picture->resizeToWidth(125); 

    $picture->save('../images/125x125/'.$file, $picture->image_type); 

    unlink('../tmp/'.$file); 

    $thumbnail = $file; 

    $new_list = array(); 

    while($listlength > $i) { 

     $path = parse_url($list[$i], PHP_URL_PATH); 

     $extension = pathinfo($path, PATHINFO_EXTENSION); 

     $file = $filename.'.'.$extension; 

     file_put_contents('../tmp/' . $file, file_get_contents($list[$i])); 

     $picture = new pic_resize(); 

     $picture->load('../tmp/'.$file); 

     $picture->resizeToWidth(640); 

     $picture->save('../images/640x320/'.$file, $picture->image_type); 

     $picture->resizeToWidth(310); 

     $picture->save('../images/310x205/'.$file, $picture->image_type); 

     unlink('../tmp/'.$file); 

     array_push($new_list, $file); 

     $i++; 
    } 
    $screenshots = implode($new_list, ','); 

回答

0
$a = file_get_contents("http://a513.phobos.apple.com/us/r1000/094/Purple/v4/d4/e4/02/d4e402a3-a485-4d4c-cf9b-90b0af391626/mzl.wbbwbbab.png"); 
echo strlen($a); 

對我的作品好。它可能會導致您的環境出錯(防火牆,wiruses,ISP修改HTTP請求等)。嘗試粘貼在瀏覽器中點擊此鏈接:

http://a513.phobos.apple.com/us/r1000/094/Purple/v4/d4/e4/02/d4e402a3-a485-4d4c-cf9b-90b0af391626/mzl.wbbwbbab.png

你看到的圖像或錯誤?您可以嘗試使用其他工具下載映像,例如在unix ot php cUrl上的wget命令。請注意,這不是代碼錯誤 - 這是我的服務器響應與HTTP代碼400 - 錯誤的請求,所以你連接到圖像服務器,但由file_get_contents產生的HTTP GET請求無效。