-2

I'm trying to list the size of JS files on a website by adding website URL using PHP language.

But it can't read links that contain something like ../

Noor B.
  • 1
  • 3
  • You should use absolute-ish paths, with `$_SERVER['DOCUMENT_ROOT'].'/path/to/js/file'`. – aynber Mar 19 '18 at 17:42
  • no $_SERVER['DOCUMENT_ROOT'] returns my server but I want the path of the submitted url – Noor B. Mar 19 '18 at 17:57
  • If it's the remote server's path, you're going to have a lot more headaches. You'll have to compare the js path to the url of the page you're requesting. – aynber Mar 19 '18 at 18:03
  • @aynber I wouldn't recommend relying on `$_SERVER['DOCUMENT_ROOT']`. 1) It requires the script to be executed via an HTTP server, and 2) It relies on the HTTP server actually populating that configuration. There are better ways to reference absolute file paths that don't introduce dependencies on other systems. – Phil Mar 20 '18 at 06:19
  • @Phil My initial comment, I was under the impression it was from a form, and they were getting something from the local server. But now it sounds like they might be scraping another site, but I'm not sure. – aynber Mar 20 '18 at 12:16

1 Answers1

1

try this it works for me well

file_get_contents(__DIR__ . '/../../../test.js');

__DIR__ is a useful magic constant.

Phil
  • 141,914
  • 21
  • 225
  • 223