2

Background:
We have a paid service that we download zip files from. The zip files are in a very predictable format like this

"file_<date>_Level1.zip"
"file_<date>_Level3.zip"
"file_<date>_Level7.zip"
"file_<date>_PG.zip"

The only interface to download there files are from a website that uses adobe flash and you have to traverse a navigation tree 4 levels deep, download a file, then traverse another tree 4 levels deep and download the next file. There are over 100 files and it takes a user about 1.5 days to do this.

Because the file names are very predictable - and have been for years, I am trying to generate a webpage that they can open locally on their laptop and the links point directly to the download, so when they click on the link it automatically downloads the file. something like:

www.contoso.com/resources/downloads/file__<date>_Level1.zip
www.contoso.com/resources/downloads/file__<date>_Level3.zip
www.contoso.com/resources/downloads/file__<date>_PG.zip

Every week, these files are updated and not all of the levels are there, so when I dynamically generate these links, about 25% of them fail.

Question:

I am looking for a way to check if the download link is valid, and if not perhaps gray it out or add an image that is now visible that is like a red x indicating that the file is not there.

What I tried:

I tried using AJAX, jquery, php, all kinds of things, and I mostly ran into what I believe are CORS issues? About cross-domain requests? I have spent probably 2 days on this with tons of trial and error and research. It seems like it would be such a simple thing: "Does the zip file exist at this url?"

Since the webpage with download links is really just a simple html file that they will probably have on their desktop, I also tried disabling CORS with something like chrome --disable-web-security --user-data-dir and other options.

So frustrated, any help is appreciate, also my level of AJAX, jquery, php etc. is basic, my career has been spent in SQL Server, Azure, etc.

Thanks, Matt

MChandler
  • 21
  • 1
  • Take a look at https://stackoverflow.com/questions/981954/how-can-one-check-to-see-if-a-remote-file-exists-using-php. Using php / the server also eliminates the CORS problems. – jeroen Feb 07 '18 at 15:34
  • Is it possible to download these files with *curl* or *wget* from *php* calling the function **shell_exec**? – Pierre François Feb 07 '18 at 15:35
  • php and curl is fine for this, a test could look like `function url_exists($url) { if (!$fp = curl_init($url)) return false; return true;}` and grep it with: `file_put_contents("yourlocal.zip", file_get_contents('the_remote_zipurl'));` – axel.michel Feb 07 '18 at 15:38
  • So I didn't mention, but one of the reasons I am using a webpage is that it is https and requires a login, but if I log in from chrome and open a new tab with this local webpage with the download links, it keeps the authentication in-tact and still downloads them, I am currently looking at the php option and the link from jeroen, thanks for suggestions so far. I will report back – MChandler Feb 07 '18 at 15:42
  • `curl --user user:pass https://ur`l might work, if the site uses a cookie to store, have a look at: https://stackoverflow.com/questions/12399087/curl-to-access-a-page-that-requires-a-login-from-a-different-page – axel.michel Feb 07 '18 at 15:54
  • So I tried running the php and it just shows code on the page so I was searching around and found this link: https://stackoverflow.com/questions/5121495 it referencing requiring using http instead of file:/// otherwise the php wont run, and since its just a local html/php file, it wont work, right? I tried referencing it as localhost or 127.0.0.1 and no luck – MChandler Feb 07 '18 at 16:16
  • I also created a local share and tried to reference it as sharename/folder/filename and no luck – MChandler Feb 07 '18 at 16:27

0 Answers0