jDownloadsownloads.com

Advertisement
Advertisement:

Author Topic: Send Downloads using the PHP Script [Solved}  (Read 4712 times)

0 Members and 1 Guest are viewing this topic.

Offline idfake

  • Newbie
  • *
  • Posts: 7
Send Downloads using the PHP Script [Solved}
« on: 04.02.2015 11:24:51 »
When choosing No for "Send Downloads using the PHP Script?" downloads don't work.
They get redirected to "http://physicaldrive/physicalpath_to_uploadfolder/file.pdf".
« Last Edit: 02.06.2015 10:59:52 by ColinM »

Offline evilshinobi

  • Jr. Member
  • **
  • Posts: 50
Re: Send Downloads using the PHP Script
« Reply #1 on: 04.02.2015 12:50:39 »
Hi idfake

I have the same issue: http://www.jdownloads.com/forum/index.php?topic=7816
The topic is on german, but the problem is somewhere in ".../components/com_jdownloads/controllers/download.php"

Somehow the variables $host and $path isn't working for me and you... I edited the code on line 781 for myself (look at Reply 9 in the topic above), so it works for me right now.
But I'm glad that I'm not the only one.

Offline idfake

  • Newbie
  • *
  • Posts: 7
Re: Send Downloads using the PHP Script
« Reply #2 on: 04.02.2015 13:24:35 »
I dug into it a bit.
You're right, the problems is components/com_jdownloads/controllers/download.php.

There are two problems (for me).
1.) Windows as Host OS. This means $_SERVER["DOCUMENT_ROOT"] returns the path with backslashes, but $filename_direct uses normal slashes.
2.) Joomla on subdir. My Joomla runs on http://host/joomla. This leads to $_SERVER["DOCUMENT_ROOT"] returning the wrong root. http://host instead of http://host/joomla.

I changed the following:
Code: [Select]
            // if set the option for direct link to the file
            if (!$jlistConfig['use.php.script.for.download']){
                $root = rtrim($_SERVER["DOCUMENT_ROOT"], "/");
                $root = rtrim($_SERVER["DOCUMENT_ROOT"], "\\");
                $host = $_SERVER["HTTP_HOST"].'/';
                $filename_direct = str_replace($root, $host, $filename_direct);
                $filename_direct = str_replace('//', '/', $filename_direct);
                if (strpos('http://', $filename_direct) === false && strpos('https://', $filename_direct) === false && strpos('ftp://', $filename_direct) === false){
                    $filename_direct = 'http://'.$filename_direct;
                }
                $app->redirect($filename_direct);
to
Code: [Select]
            // if set the option for direct link to the file
            if (!$jlistConfig['use.php.script.for.download']){
$root = str_replace('\\', '/', $_SERVER["APPL_PHYSICAL_PATH"]);
                $root = rtrim($root, "/");
                $host = $_SERVER["HTTP_HOST"].'/'.JURI::root(true);
                $filename_direct = str_replace($root, $host, $filename_direct);
                $filename_direct = str_replace('//', '/', $filename_direct);
                if (strpos('http://', $filename_direct) === false && strpos('https://', $filename_direct) === false && strpos('ftp://', $filename_direct) === false){
                    $filename_direct = 'http://'.$filename_direct;
                }
                $app->redirect($filename_direct);

This works for me. I hope Arno can take a look at this.

Offline Arno

  • Administrator
  • ***
  • Posts: 12.110
    • jDownloads.com
Re: Send Downloads using the PHP Script
« Reply #3 on: 04.02.2015 13:54:53 »
Hi Guys,
seems that it is a problem when Joomla is installed in a sub folder.
So i will test it new in a sub folder and with your modification.

Quote
1.) Windows as Host OS. This means $_SERVER["DOCUMENT_ROOT"] returns the path with backslashes, but $filename_direct uses normal slashes.
I think that is not really a problem. Both should works proper.
Best Regards / Gruß
Arno
Please make a Donation for jDownloads and/or write a review on the Joomla! Extensions directory!

Offline Arno

  • Administrator
  • ***
  • Posts: 12.110
    • jDownloads.com
Re: Send Downloads using the PHP Script
« Reply #4 on: 04.02.2015 15:16:51 »
I have this now tested with a joomla which is installed in a sub folder: localhost/subfolder/joomla/
But i can not see a problem as here works it very fine.  ::)
Best Regards / Gruß
Arno
Please make a Donation for jDownloads and/or write a review on the Joomla! Extensions directory!

Offline idfake

  • Newbie
  • *
  • Posts: 7
Re: Send Downloads using the PHP Script
« Reply #5 on: 05.02.2015 08:57:27 »
Hi Guys,
seems that it is a problem when Joomla is installed in a sub folder.
So i will test it new in a sub folder and with your modification.
I think that is not really a problem. Both should works proper.
Hi Arno.

It doens't.  DOCUMENT_ROOT returns "C:\path\to\joomla". But filename_direct ist constructed as "C:/path/to/joomla/jdownloads/file.pdf".
The different slashes let the
Code: [Select]
str_replace($root, $host, $filename_direct); fail always.


PHP 5.6.5
Joomla 2.5.28
IIS 8.5
JDownloads 2.5.24beta

Offline evilshinobi

  • Jr. Member
  • **
  • Posts: 50
Re: Send Downloads using the PHP Script
« Reply #6 on: 05.02.2015 09:57:46 »

The different slashes let the
Code: [Select]
str_replace($root, $host, $filename_direct); fail always.

Ah thats why the $host was never printed. To echo $host alone was no problem, but the combination didn't worked for me either.

Offline idfake

  • Newbie
  • *
  • Posts: 7
Re: Send Downloads using the PHP Script
« Reply #7 on: 05.02.2015 10:01:32 »
I have this now tested with a joomla which is installed in a sub folder: localhost/subfolder/joomla/
But i can not see a problem as here works it very fine.  ::)
My config is like this:
example.com => c:\wwwroot\mainsite
example.com/joomla => c:\wwwroot\joomla

The DOCUMENT_ROOT for "example.com/joomla" is  "c:\wwwroot\mainsite", whereas APPL_PHYSICAL_PATH is the correct "c:\wwwroot\joomla"
Maybe it's an IIS thing.


PHP 5.6.5
Joomla 2.5.28
IIS 8.5
JDownloads 2.5.24beta

Offline ColinM

  • Moderator
  • *
  • Posts: 3.152

Offline Arno

  • Administrator
  • ***
  • Posts: 12.110
    • jDownloads.com
Re: Send Downloads using the PHP Script
« Reply #9 on: 07.02.2015 02:30:10 »
Hi

Yes I also think it is an IIS thing
try http://stackoverflow.com/questions/189113/how-can-i-get-the-current-pages-full-url-on-a-windows-iis-server
Colin

Hi Colin,
i understand not really the complete discussion on this page. Maybe can you post here the 'most recommended' way from this page?  ;)
Best Regards / Gruß
Arno
Please make a Donation for jDownloads and/or write a review on the Joomla! Extensions directory!

Offline idfake

  • Newbie
  • *
  • Posts: 7
Re: Send Downloads using the PHP Script
« Reply #10 on: 09.02.2015 12:12:32 »
Hi Colin,
i understand not really the complete discussion on this page. Maybe can you post here the 'most recommended' way from this page?  ;)

Well, i'm not Colin, but i recommend at least this small change:
replace line 762, 763 components\com_jdownloads\controllers\download.php
Code: [Select]
$root = rtrim($_SERVER["DOCUMENT_ROOT"], "/");
$root = rtrim($_SERVER["DOCUMENT_ROOT"], "\\");
witch
Code: [Select]
$root = str_replace('\\', '/', $_SERVER["DOCUMENT_ROOT"]);
$root = rtrim($root, "/");

This fixes the issue for IIS 8.5  when Joomla is run on the root dir while beeing minimally invasive.



Offline Arno

  • Administrator
  • ***
  • Posts: 12.110
    • jDownloads.com
Re: Send Downloads using the PHP Script
« Reply #11 on: 09.02.2015 15:40:04 »
Okay. Thanks i will try this.
[Code revised - different line nos]
« Last Edit: 02.06.2015 10:59:18 by ColinM »
Best Regards / Gruß
Arno
Please make a Donation for jDownloads and/or write a review on the Joomla! Extensions directory!

 

Advertisement