Author Topic: DOWNLOAD BUTTON & ADMIN TOP 5 PICTURE HITS ERRORS  (Read 13005 times)

0 Members and 1 Guest are viewing this topic.

Offline Alain

  • Newbie
  • *
  • Posts: 24
    • View Profile
DOWNLOAD BUTTON & ADMIN TOP 5 PICTURE HITS ERRORS
« on: June 16, 2002, 10:33:20 PM »
Hi, first, thank you very much!

2 things however that need to be solved :

if I click on the DOWNLOAD button then it is starting to download but it is only downloading the first segment of the file : never more than 1000 bytes then it is finishing. Result : a file that should be 50K heavy is downloaded at only 1K so obviously the file is corrupted (this is NOT A REMOTE/URL file, it is a local file).

Environment : Windows 2000 + Apache 1.3 + PHP 4

I have manually debugged DOWNLOAD.PHP and it seems that the file length is correctly checked but then in the code, this value is missed and so the browser is only downloading a small part of the picture. The resulted picture is simply the header of the picture.

Also in the admin. panel, if I look at the TOP 5 PICTURE HITS then the total is always 0 (Total:0) as if it was unable to make the sum of the hits.

Thank you!!!

Offline Nicky

  • Administrator
  • 4images Guru
  • *****
  • Posts: 3.195
    • View Profile
DOWNLOAD BUTTON & ADMIN TOP 5 PICTURE HITS ERRORS
« Reply #1 on: June 16, 2002, 11:22:40 PM »
TOP 5 Hits:

admin/home.php change line 251:
Code: [Select]

  $row = $site_db->query_firstrow();

to
Code: [Select]

  $row = $site_db->query_firstrow($sql);
cheers
Nicky
Your first three "must do" before you ask a question ! (© by V@no)
- please read the Forum Rules ...
- please study the FAQ ...
- please try to Search for your answer ...

nicky.net 4 4images
Signature stolen from mawenzi

Offline Jan

  • Administrator
  • 4images Guru
  • *****
  • Posts: 5.024
    • View Profile
    • 4images - Image Gallery Management System
DOWNLOAD BUTTON & ADMIN TOP 5 PICTURE HITS ERRORS
« Reply #2 on: June 16, 2002, 11:29:38 PM »
What PHP Version are exactly running? Can you post a URL?

Greets Jan
Your first three "must do" before you ask a question:
1. Forum rules
2. FAQ
3. Search

Offline Alain

  • Newbie
  • *
  • Posts: 24
    • View Profile
The versions...
« Reply #3 on: June 16, 2002, 11:36:45 PM »
apache 1.3.24 - php 4.2.0

Also I have corrected at the line 251 the appropriate file but what is the meaning of this :

Top 5 images by hits (Total: 359)

when I have :

Top 5 categories by hits (Total: 56)

I can't unfortunately post the URL as it is an intranet site.

Thanks!

AL

Offline Nicky

  • Administrator
  • 4images Guru
  • *****
  • Posts: 3.195
    • View Profile
DOWNLOAD BUTTON & ADMIN TOP 5 PICTURE HITS ERRORS
« Reply #4 on: June 16, 2002, 11:39:14 PM »
TOP 5 viewed Categories
TOP 5 viewed Images
cheers
Nicky
Your first three "must do" before you ask a question ! (© by V@no)
- please read the Forum Rules ...
- please study the FAQ ...
- please try to Search for your answer ...

nicky.net 4 4images
Signature stolen from mawenzi

Offline Alain

  • Newbie
  • *
  • Posts: 24
    • View Profile
Additional info...
« Reply #5 on: June 16, 2002, 11:42:08 PM »
In the download.php :

  $file_size = filesize($file_path);
    $fp = fopen($file_path, "r");
    if ($fp) {
      $file_data = fread($fp, $file_size);
      fclose($fp);
    }

$file_size is OK

  if (eregi("MSIE", getenv("HTTP_USER_AGENT"))) {
    $disposition = ($action != "zip" && $action != "lightbox") ? 'attachment' : 'inline';
    header("Content-Disposition: $disposition; filename=".$file['file_name']."\n");
    header("Content-Type: application/x-ms-download\n");
    header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
    header("Pragma: public");
  }
  elseif (eregi("Opera", getenv("HTTP_USER_AGENT"))) {
    header("Content-Disposition: attachment; filename=".$file['file_name']."\n");
    header("Content-Type: application/octetstream\n");
    header("Cache-Control: no-cache");
    header("Pragma: no-cache");
  }
  else {
    header("Content-Disposition: attachment; filename=".$file['file_name']."\n");
    header("Content-Type: application/octet-stream\n");
    header("Cache-Control: no-cache");
    header("Pragma: no-cache");
  }
  header("Last Modified: ".gmdate("D, d M Y H:i:s")."GMT\n");
  header("Expires: 0\n");
  header("Content-Length: ".$file['file_size']."\n");

  if (eregi("Mac", getenv("HTTP_USER_AGENT"))) {
    header("Content-Transfer-Encoding: binary\n");
    header("Accept-Ranges: bytes\n");
    header("Connection: close\n");
  }
  echo $file['file_data'];

$file['file_size'] is corresponding to the file size that I've downloaded so it means that we may just need to replace this incorrect value (between 0-1000 bytes) by the correct value (above) which is between (1000-100000 bytes) - the correct file size - for the browser.

I hope it will help! :)

AL

Offline Jan

  • Administrator
  • 4images Guru
  • *****
  • Posts: 5.024
    • View Profile
    • 4images - Image Gallery Management System
DOWNLOAD BUTTON & ADMIN TOP 5 PICTURE HITS ERRORS
« Reply #6 on: June 16, 2002, 11:42:18 PM »
Hmm..hard to say from here. Can you put a copy of our phpinfo() on the net? Or mail me the copy to jan@4homepages.de

Greets Jan
Your first three "must do" before you ask a question:
1. Forum rules
2. FAQ
3. Search

Offline Alain

  • Newbie
  • *
  • Posts: 24
    • View Profile
PHPINFO
« Reply #7 on: June 16, 2002, 11:50:42 PM »

Offline Alain

  • Newbie
  • *
  • Posts: 24
    • View Profile
About the hits
« Reply #8 on: June 16, 2002, 11:58:46 PM »
I may not understand 'cause I worked hard today but...

Top 5 categories by hits (Total: 60)

X = 43
Y = 17

Top 5 images by hits (Total: 490)

A = 17
B = 10
C = 8
D = 8
E = 8
F = 8

490 isn't incorrect???

Offline Nicky

  • Administrator
  • 4images Guru
  • *****
  • Posts: 3.195
    • View Profile
DOWNLOAD BUTTON & ADMIN TOP 5 PICTURE HITS ERRORS
« Reply #9 on: June 17, 2002, 12:03:38 AM »
Top 5 images by hits (Total: 490)

First 5:
A = 17
B = 10
C = 8
D = 8
E = 8

Others:
F = 8
G = 15
I = 44
J = 7
......

= Total 490
cheers
Nicky
Your first three "must do" before you ask a question ! (© by V@no)
- please read the Forum Rules ...
- please study the FAQ ...
- please try to Search for your answer ...

nicky.net 4 4images
Signature stolen from mawenzi

Offline Alain

  • Newbie
  • *
  • Posts: 24
    • View Profile
OK
« Reply #10 on: June 17, 2002, 12:11:49 AM »
OK, I have also checked the appropriate table and I was just surprised by the number of hits encountered for the pictures  :wink:

Just that download thing which is I think not so hard to solve  :twisted:

Offline Jan

  • Administrator
  • 4images Guru
  • *****
  • Posts: 5.024
    • View Profile
    • 4images - Image Gallery Management System
DOWNLOAD BUTTON & ADMIN TOP 5 PICTURE HITS ERRORS
« Reply #11 on: June 17, 2002, 07:54:10 AM »
Hmmm.....no idea at the moment. I think you have to test a little bit around with the headers.

I think $file['file_size'] should be correct. The value is set here:

Code: [Select]
$file['file_size'] = strlen($file['file_data']);

Try to remove:

Code: [Select]
header("Content-Length: ".$file['file_size']."\n");

Or maybe try to remove the \n in the header functions.
Code: [Select]
header("Content-Type: application/x-ms-download[b][color=red]\n[/color][/b]");

Greets Jan
Your first three "must do" before you ask a question:
1. Forum rules
2. FAQ
3. Search

Offline Alain

  • Newbie
  • *
  • Posts: 24
    • View Profile
More info...
« Reply #12 on: June 17, 2002, 02:02:23 PM »
$file['file_size']  is reporting the wrong value : never more than 1000 bytes but I tried to indicate the file size instead of this variable for the content-length but still the final file is incorrect and the downloaded file is not usable. The problem is the same with Netscape.

Offline Jan

  • Administrator
  • 4images Guru
  • *****
  • Posts: 5.024
    • View Profile
    • 4images - Image Gallery Management System
DOWNLOAD BUTTON & ADMIN TOP 5 PICTURE HITS ERRORS
« Reply #13 on: June 17, 2002, 02:25:00 PM »
Try this:

Replace in download.php

Code: [Select]
$fp = fopen($file_path, "r");
with

Code: [Select]
$fp = fopen($file_path, "rb");

Greets Jan
Your first three "must do" before you ask a question:
1. Forum rules
2. FAQ
3. Search

Offline Alain

  • Newbie
  • *
  • Posts: 24
    • View Profile
More info...
« Reply #14 on: June 17, 2002, 02:28:17 PM »
I will try this, however, you can reproduce the workflow with http://www.easyphp.org/?lang=en - EasyPHP 1.6 which is installing Apache+PHP+MySQL under Windows 2000.