up
This commit is contained in:
@@ -0,0 +1,41 @@
|
||||
<?php
|
||||
// Usage: php scripts/test_media_url.php <mediaId>
|
||||
$mediaId = $argv[1] ?? '1379066300634610';
|
||||
|
||||
// 1) JSON request (requires auth) - use local cookie session if possible
|
||||
$opts = ['http' => ['method' => 'GET', 'header' => "Accept: application/json\r\n"]];
|
||||
$ctx = stream_context_create($opts);
|
||||
$url = "http://localhost/whatsapp/api/version/media-url.php?id=" . urlencode($mediaId);
|
||||
echo "Requesting JSON -> $url\n";
|
||||
$s = @file_get_contents($url, false, $ctx);
|
||||
if ($s === false) {
|
||||
echo "JSON request failed (probably 401 if not authenticated)\n";
|
||||
} else {
|
||||
echo $s . "\n";
|
||||
}
|
||||
|
||||
// 2) Direct GET (simulate browser) should receive a Location header (we can't follow in this simple test)
|
||||
$headers = get_headers($url, 1);
|
||||
if ($headers) {
|
||||
echo "\nResponse headers:\n";
|
||||
print_r($headers);
|
||||
} else {
|
||||
echo "No headers received (server unreachable)\n";
|
||||
}
|
||||
|
||||
// 3) Proxy download test
|
||||
$downloadUrl = $url . '&download=1';
|
||||
echo "\nDownload test -> $downloadUrl\n";
|
||||
$opts2 = ['http' => ['method' => 'GET']];
|
||||
$ctx2 = stream_context_create($opts2);
|
||||
$stream = @fopen($downloadUrl, 'r', false, $ctx2);
|
||||
if (!$stream) {
|
||||
echo "Download request failed (check server or token)\n";
|
||||
} else {
|
||||
$meta = stream_get_meta_data($stream);
|
||||
echo "Opened stream, meta keys: " . implode(',', array_keys($meta)) . "\n";
|
||||
// Read a small part
|
||||
$part = fread($stream, 200);
|
||||
echo "First bytes:\n" . substr($part,0,200) . "\n";
|
||||
fclose($stream);
|
||||
}
|
||||
Reference in New Issue
Block a user