I am using this code to display file size in my theme and trying to get the file url from a custom field but its not working with full url it only need path, can any one tell me how can I use this with full url ? Â WORKING <?php echo filesize('wp-content/uploads/insurance-quotes-595x286.jpg'); ?> bytes PHP: Â NOT WORKING <?php echo filesize('http://www.digmlm.com/wp-content/uploads/insurance-quotes-595x286.jpg'); ?> bytes PHP: IF POSSIBLE ALSO TELL HOW TO DISPLAY IN 'Mbs' INSTEAD OF BYTES
I found this solution BUT its not working with custom field Please help:- ORIGINAL CODE <?php $remoteFile = 'http://us.php.net/get/php-5.2.10.tar.bz2/from/this/mirror'; $ch = curl_init($remoteFile); curl_setopt($ch, CURLOPT_NOBODY, true); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_HEADER, true); curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true); //not necessary unless the file redirects (like the PHP example we're using here) $data = curl_exec($ch); curl_close($ch); if ($data === false) { echo 'cURL failed'; exit; } $contentLength = 'unknown'; $status = 'unknown'; if (preg_match('/^HTTP\/1\.[01] (\d\d\d)/', $data, $matches)) { $status = (int)$matches[1]; } if (preg_match('/Content-Length: (\d+)/', $data, $matches)) { $contentLength = (int)$matches[1]; } echo 'HTTP Status: ' . $status . "\n"; echo 'Content-Length: ' . $contentLength; ?> PHP: I MODIFIED THE CODE:- <?php $remoteFile = '<?php $values = get_post_custom_values("audio"); echo $values[0]; ?>'; $ch = curl_init($remoteFile); curl_setopt($ch, CURLOPT_NOBODY, true); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_HEADER, true); curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true); //not necessary unless the file redirects (like the PHP example we're using here) $data = curl_exec($ch); curl_close($ch); if ($data === false) { echo 'cURL failed'; exit; } $contentLength = 'unknown'; $status = 'unknown'; if (preg_match('/^HTTP\/1\.[01] (\d\d\d)/', $data, $matches)) { $status = (int)$matches[1]; } if (preg_match('/Content-Length: (\d+)/', $data, $matches)) { $contentLength = (int)$matches[1]; } echo 'HTTP Status: ' . $status . "\n"; echo 'Content-Length: ' . $contentLength; ?> PHP: I Found this here http://php.net/manual/en/function.filesize.php