Jump to content

New install - Digital download link not working (500 internal error)


Recommended Posts

Hello!

 

I've just installed CubeCart V6 on a new Subdomain (nothing else installed on this subdomain).

Everything seem to be working fine, except that I can't get the download link to work for digital purchase (100% of my shop will be digital files).

 

Apparently, I'm getting a 500 internal error when I click on the link generated after the purchase (sent by mail) or in the customer Digital Download section.

 

And this happens wherever the file location is  :errm:

I've tried with an uploaded file, a custom path leading to a directory /home/username/folder/filename, as well as a link to an externally hosted file (http link)... nothing

 

I'm a bit lost right now, I don't know what's wrong (I'd have expected at least the http link file to work since the file isn't hosted on my server... but not even that).

It's seems the generated link is the problem...

 

Any help would be greatly appreciated!

 

Thanks a lot in advance

DR

Link to comment
Share on other sites

Welcome Darth Ryô! Glad to see you made it to the forums.
 

Will you please read the following and create this file. When you click a download link, if there is a problem with the PHP code, we should have the error logged in the error_log file.

 

Or, if your hosted account already has PHP's error logging enabled and you have access to the error_log, perhaps through your hosted account's control panel, then let us know what errors are getting logged.

 

Depending how PHP is interfacing with the web server, a web server status 500ISE will result even though the fault is with PHP. On the other hand, it could very well be a problem with a web server configuration or a directive in the .htaccess file that is tripping the web server with the URL for the download.

Link to comment
Share on other sites

Hello,

 

Alright, turned the error logging on.

[10-Apr-2015 17:11:35 Europe/London] PHP Fatal error:  Undefined class constant 'FM_DL_ERROR_NOFILE' in /home/darthryo/public_html/goth-3designs/classes/filemanager.class.php on line 397
[10-Apr-2015 17:14:21 Europe/London] PHP Fatal error:  Undefined class constant 'FM_DL_ERROR_NOFILE' in /home/darthryo/public_html/goth-3designs/classes/filemanager.class.php on line 397
[10-Apr-2015 17:21:18 Europe/London] PHP Warning:  array_merge() [<a href='http://docs.php.net/manual/en/function.array-merge.php'>function.array-merge.php</a>]: Argument #2 is not an array in /home/darthryo/public_html/goth-3designs/admin/sources/products.index.inc.php on line 1266
[10-Apr-2015 17:21:18 Europe/London] PHP Warning:  natcasesort() expects parameter 1 to be array, null given in /home/darthryo/public_html/goth-3designs/admin/sources/products.index.inc.php on line 1269
[10-Apr-2015 17:21:18 Europe/London] PHP Warning:  Invalid argument supplied for foreach() in /home/darthryo/public_html/goth-3designs/admin/sources/products.index.inc.php on line 1270
[10-Apr-2015 17:21:51 Europe/London] PHP Warning:  Invalid argument supplied for foreach() in /home/darthryo/public_html/goth-3designs/classes/ajax.class.php on line 130
[10-Apr-2015 17:21:55 Europe/London] PHP Warning:  array_merge() [<a href='http://docs.php.net/manual/en/function.array-merge.php'>function.array-merge.php</a>]: Argument #2 is not an array in /home/darthryo/public_html/goth-3designs/admin/sources/products.index.inc.php on line 1266
[10-Apr-2015 17:21:55 Europe/London] PHP Warning:  natcasesort() expects parameter 1 to be array, null given in /home/darthryo/public_html/goth-3designs/admin/sources/products.index.inc.php on line 1269
[10-Apr-2015 17:21:55 Europe/London] PHP Warning:  Invalid argument supplied for foreach() in /home/darthryo/public_html/goth-3designs/admin/sources/products.index.inc.php on line 1270
[10-Apr-2015 17:23:51 Europe/London] PHP Fatal error:  Undefined class constant 'FM_DL_ERROR_NOFILE' in /home/darthryo/public_html/goth-3designs/classes/filemanager.class.php on line 397

The lines in red correspond to when I click on the digital download link sent by mail.

First 2 lines are on a product with a custom path on my server, the last one is o a product with a file uploaded in Cubecart directly.

(I guess the other warning are not critical...)

 

See below the extract of my filemanager.class.php (in red the line 397 mentioned in the log).

Unfortunately this is really not my area of expertise and I don't understand the issue.

 

Thanks again for your help :)

 

                              

    /**
     * Deliver download file
     *
     * @param string $access_key
     * @param string $error
     * @return bool
     */
    public function deliverDownload($access_key = false, &$error = null) {
        if ($this->_mode == self::FM_FILETYPE_DL && $access_key) {
            if (($downloads = $GLOBALS['db']->select('CubeCart_downloads', false, array('accesskey' => $access_key))) !== false) {
                $download = $downloads[0];
                if (($summary = $GLOBALS['db']->select('CubeCart_order_summary', false, array('cart_order_id' => $download['cart_order_id']))) !== false) {
                    // Order/Download Validation
                    // Download has expired
                    if ($download['expire']>0 && $download['expire'] < time())  $error = self::FM_DL_ERROR_EXPIRED;
                    // Order hasn't been paid for
                    if (!in_array((int)$summary[0]['status'], array(2, 3)))     $error = self::FM_DL_ERROR_PAYMENT;
                    // Maximum download limit has been reached
                    if ($GLOBALS['config']->get('config', 'download_count') > 0 && (int)$download['downloads'] >= $GLOBALS['config']->get('config', 'download_count')) $error = self::FM_DL_ERROR_MAXDL;
                    if (!empty($error)) return false;
                    if ($data = $this->getFileInfo($download['product_id']) !== false) {


                        // Deliver file contents
                        if (isset($data['file']) && ($data['is_url'] || file_exists($data['file']))) {
                            if ($is_url) {
                                $GLOBALS['db']->update('CubeCart_downloads', array('downloads' => $download['downloads']+1), array('digital_id' => $download['digital_id']));
                                httpredir($file);
                                return true;
                            } else {
                                ob_end_clean();
                                if (!is_file($file) or connection_status()!=0) return false;

                                header("Expires: ".gmdate("D, d M Y H:i:s", mktime(date("H")+2, date("i"), date("s"), date("m"), date("d"), date("Y")))." GMT");
                                header("Last-Modified: ".gmdate("D, d M Y H:i:s")." GMT");
                                header('Content-Disposition: attachment; filename="'.basename($file).'"');
                                header("Content-Type: application/octet-stream");
                                header("Content-Transfer-Encoding: binary");
                                ## IE 7 Fix
                                header('Vary: User-Agent');

                                if (($openfile = fopen($file, 'rb')) !== false) {
                                    while (!feof($openfile)) {
                                        set_time_limit(120);
                                        echo fread($openfile, 8192);
                                        flush();
                                    }
                                    fclose($openfile);
                                }
                                if (!connection_status() && !connection_aborted()) {
                                    $GLOBALS['db']->update('CubeCart_downloads', array('downloads' => $download['downloads']+1), array('digital_id' => $download['digital_id']));
                                    return true;
                                }
                            }
                        }
                        ## File doesn't exist
                        $error = self::FM_DL_ERROR_NOFILE;
                        return false;
                    }
                    ## Product record doesn't exist
                    $error = self::FM_DL_ERROR_NOPRODUCT;
                    return false;
                }
            }
            // Download record doesn't exist
            $error = self::FM_DL_ERROR_NORECORD;
        }
        return false;
    }

Link to comment
Share on other sites

Interesting!

If possible, let us know the exact version of PHP your site is running: admin, Dashboard, Store Overview tab.

There are two parts to this apparent problem:
Line 36: if (!defined('FM_DL_ERROR_NOFILE'))  define('FM_DL_ERROR_NOFILE', 3);
and anyplace that uses self:: to reference that constant.

I think there may be a version(s) of PHP that does not couple defining a constant in one class's function, and then be expected to see it everywhere in that class. I'll consult the PHP docs and discuss it with the developers.

If the version of PHP is early 5.2, you could try to upgrade your site's version of PHP to 5.4 or better.

Or, in the meantime, try this (I haven't verified that this will work):

Find and delete:
        // Define some constants
        if (!defined('FM_DL_ERROR_EXPIRED')) define('FM_DL_ERROR_EXPIRED', 1);
        if (!defined('FM_DL_ERROR_MAXDL'))  define('FM_DL_ERROR_MAXDL', 2);
        if (!defined('FM_DL_ERROR_NOFILE'))  define('FM_DL_ERROR_NOFILE', 3);
        if (!defined('FM_DL_ERROR_NOPRODUCT')) define('FM_DL_ERROR_NOPRODUCT', 4);
        if (!defined('FM_DL_ERROR_NORECORD')) define('FM_DL_ERROR_NORECORD', 5);
        if (!defined('FM_DL_ERROR_PAYMENT')) define('FM_DL_ERROR_PAYMENT', 6);

Find near the beginning of the file:
    const FM_FILETYPE_IMG = 1;
    const FM_FILETYPE_DL = 2;

Add After:
        const FM_DL_ERROR_EXPIRED = 1;
        const FM_DL_ERROR_MAXDL = 2;
        const FM_DL_ERROR_NOFILE = 3;
        const FM_DL_ERROR_NOPRODUCT = 4;
        const FM_DL_ERROR_NORECORD = 5;
        const FM_DL_ERROR_PAYMENT = 6;

The other warnings can be looked into later.

Link to comment
Share on other sites

Ok, for PHP Version => 5.5.23

So no upgrade needed.

 

Then I tried the above code change (commented out the Error define lines and added the constants lines).

Well, now the link works but just send me to the page HOME / YOUR ACCOUNT / DIGITAL DOWNLOADS

with an error message (see attached picture):

The following errors were detected:

  • It has not been possible to locate the download file.

 

Aside of the warnings already mentioned before, there is no new PHP Fatal error in the error.log

 

Again, I've tried that 3 time with the same results:

- Uploaded file

- Custom path on server

- Custom path toward a file on internet (http link)

 

If you look at the attached screenshot, the name of the target file is however properly displayed to the user... so it can somehow see the target but unable to download it (each download attempt just refreshes the page and error message).

 

Thanks again!

 

 

Capture.JPG

Link to comment
Share on other sites

Good, no more errors. Now we need to figure out where CubeCart believes the file to be.

In the file /classes/filemanager.class.php, near line 365:

Find:
if (isset($data['file']) && ($data['is_url'] || file_exists($data['file']))) {

Add on a new line after:
trigger_error('The file is at: ' . $data['file']);

When you next look at the error_log file, it should have an entry that reads as above.

Link to comment
Share on other sites

  • 3 weeks later...

Like Darth I'm experiencing identical problems with broken digital downloads, as well as links from the home page creating 500 errors (are these errors related?).

My site is running a  vanilla version 6.0.4 with all in 1 shipping and paypal modules. I'm selling sheet music for download. No customisation whatsoever.

Reading through this thread, it's good to see the excellent support from bsmither (as usual) but at present until there is some assurance of an effective fix, I'm not keen on editing the source files.  Have been a user since v3 and sadly my recollections are that download functionality seems to have been inadequately tested on some releases. (Regression testing anyone?)

Is this download bug a feature of this version, has anyone else noticed it? Will there be another CC release to fix it?

Link to comment
Share on other sites

If the download link is of the proper format, then the 500ISE errors from links on the homepage are probably not related.

However, we must come to know what is causing the errors.

Please read this post, create the file, and report back with whatever the log file has in it.

Your hosting account may have a web server error log. There may be something in there.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...