Vücut indirmeden önce CURL başlıklarını Kolu

2 Cevap php

(Bu durumda kıvırmak daha iyi bir alternatif olmadığı sürece) PHP ve CURL kullanarak, bir php fonksiyonu dosyayı indirmeden önce başlık yanıtı işlemek olması mümkündür?

Örneğin:

Ben indirme ve süreçler adresler kullanıcı tarafından verilen bir komut dosyası var. Dosya benim sürecinde (bir metin dosyası, çok büyük, vb) için geçerli değilse, CURL istek dosya indirirken sunucu atıklar zaman önce iptal olacağını ben bir onay eklemek istiyorum.

Update: Solution PEAR class HTTP_Request2: http://pear.php.net/package/HTTP%5FRequest2/ Gives you the ability to set observers to the connection and throw exceptions to cancel anytime. Works perfectly for my needs!

2 Cevap

CURL kullanarak, geçerli ise o (statü 200), başlıklarını kontrol etmek için bir HTTP HEAD isteği yapmak tam bir HTTP GET isteği yapmak.

Ayarlamanız gerekir bir temel seçenek türü KAFA için istenen değiştirir ki, CURLOPT_NOBODY olduğunu

curl_setopt($ch, CURLOPT_NOBODY, true);

Sonra sorguyu yürüttükten sonra, kullanarak yapılabilir dönüş durumunu kontrol etmek gerekir curl_getinfo()

$status = curl_getinfo($ch, CURLINFO_HTTP_CODE);

Bu bunu nasıl çözebiliriz bir örnek:

// Include the Auth string in the headers
// Together with the API version being used
$headers = array(
    "Authorization: GoogleLogin auth=" . $auth,
    "GData-Version: 3.0",
);

// Make the request
curl_setopt($curl, CURLOPT_URL, "http://docs.google.com/feeds/default/private/full");
curl_setopt($curl, CURLOPT_HTTPHEADER, $headers);

$response = curl_exec($curl);
curl_close($curl);

// Parse the response
$response = simplexml_load_string($response);

// Output data
foreach($response->entry as $file)
{
       //now you can do what ever if file type is a txt
        //if($file->title =="txt")
        // do something
        else
        // do soething
    echo "File: " . $file->title . "<br />";
    echo "Type: " . $file->content["type"] . "<br />";
    echo "Author: " . $file->author->name . "<br /><br />";
}