0

I've created a php file inside the root of my site (example.com/file.php):

$head = array_change_key_case(get_headers("https://example.com/somefile.zip", TRUE));
$filesize = $head['content-length'];
echo $filesize;

When I run the file, I get the following output: 1234173 It returns the file size in kilobytes. I also use the exact same code in my WordPress theme (example.com/wp-content/themes/my_theme/single.php), but there the output is always 0.

Why? (I use this code for getting size of files in my download box)

I get the same results, when using curl. (curl is ok in my root but it havent content-length parameter in wp)

Tom
  • 4,070
  • 4
  • 22
  • 50
sajjad
  • 1
  • 2

2 Answers2

0

I think that it's wordpress problem. As you can see, your sample have a real URL. but When you need to access the my_theme/single.php, It's invalid. let's see the code first. single.php is to render the post. but Post have a permalinks. When the URL is loaded, the header is generated. but If we called the single.php, it's blocked. if you have a develop the plugin, we can see the ABS_PATH. If ABS_PATH is not defined, It means that the file is loaded wp-load.php. so If we called the single.php, It doesn't inlcude any Wordpress core. so It's invalid response and issues. In fact, we can not access special files from the theme.
For Wordpress, dispatcher function is in example.com/index.php.

0

Solved!

actuly the problem was my mistake. i use URLs somting like this:

"/Path_to_file/file.zip"

and i changed to:

"Https://wxample.com/path/file.zip"

the url must be contain site address.

thank's all

sajjad
  • 1
  • 2