„$curl_url“ - kintamasis, kuriame talpinama nuoroda (šiuo atveju „Zippyshare“). „$curl_browser“ - kintamasis, kuriame talpinama naršyklės informacija (puslapis ją priims).
Kodo veikimas paprastas, pasiima iš nurodyto puslapio informaciją („$curl_content“ kintamasis) ir ieško nurodytos žinutės „You have requested the file“, jeigu jos neranda - atvaizduoja atitinkamą pranešimą (ten turi ir parašyti kodą, kuris ištrina iš duomenų bazės įrašą).
<?php
# Puslapio nuoroda (turi būti „Zippyshare“).
$curl_url = '';
# Panaudojau „Opera 51“ naršykles informaciją.
$curl_browser = 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/64.0.3282.186 Safari/537.36 OPR/51.0.2830.55';
if (strpos($curl_url, 'zippyshare') !== false) {
$curl_handle = curl_init();
if (!curl_errno($curl_handle)) {
curl_setopt_array($curl_handle, array(
CURLOPT_URL => $curl_url,
CURLOPT_FOLLOWLOCATION => true,
CURLOPT_HEADER => false,
CURLOPT_USERAGENT => $curl_browser,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_TIMEOUT => 30
));
$curl_content = curl_exec($curl_handle);
if (curl_getinfo($curl_handle, CURLINFO_HTTP_CODE) === 200) {
if (strpos($curl_content, 'You have requested the file') === false) {
# Štai čia rašomas kodas tuo atveju, kada failas neegzistuoja.
echo 'The file does not exists.';
} else {
echo 'The file exists.';
}
} else {
echo 'Unexpected HTTP code.';
}
unset($curl_content);
} else {
echo 'Could not initialize a cURL handle.';
exit;
}
curl_close($curl_handle);
} else {
echo 'The specified uploader is not supported.';
}
?>