4images Forum & Community

4images Issues / Ausgaben => Discussion & Troubleshooting => Topic started by: Alain on June 16, 2002, 10:33:20 PM

Title: DOWNLOAD BUTTON & ADMIN TOP 5 PICTURE HITS ERRORS
Post by: Alain 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!!!
Title: DOWNLOAD BUTTON & ADMIN TOP 5 PICTURE HITS ERRORS
Post by: Nicky 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);
Title: DOWNLOAD BUTTON & ADMIN TOP 5 PICTURE HITS ERRORS
Post by: Jan on June 16, 2002, 11:29:38 PM
What PHP Version are exactly running? Can you post a URL?

Greets Jan
Title: The versions...
Post by: Alain 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
Title: DOWNLOAD BUTTON & ADMIN TOP 5 PICTURE HITS ERRORS
Post by: Nicky on June 16, 2002, 11:39:14 PM
TOP 5 viewed Categories
TOP 5 viewed Images
Title: Additional info...
Post by: Alain 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
Title: DOWNLOAD BUTTON & ADMIN TOP 5 PICTURE HITS ERRORS
Post by: Jan 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
Title: PHPINFO
Post by: Alain on June 16, 2002, 11:50:42 PM
http://perso.wanadoo.fr/myserver/phpinfo.htm
Title: About the hits
Post by: Alain 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???
Title: DOWNLOAD BUTTON & ADMIN TOP 5 PICTURE HITS ERRORS
Post by: Nicky 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
Title: OK
Post by: Alain 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:
Title: DOWNLOAD BUTTON & ADMIN TOP 5 PICTURE HITS ERRORS
Post by: Jan 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
Title: More info...
Post by: Alain 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.
Title: DOWNLOAD BUTTON & ADMIN TOP 5 PICTURE HITS ERRORS
Post by: Jan 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
Title: More info...
Post by: Alain 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.
Title: EXCELLENT!
Post by: Alain on June 17, 2002, 02:36:22 PM
It works now!  8)

Before applying, I tried to look at http://www.php.net/manual/en/function.fopen.php


Newbie advice: The little "b" for binary operations is very
essential when working with PHP4 and Apache on the win32 platform. fread()
only reads a couple of hundred bytes when reading for example an image
without "b".
// Read tempfile data into $thumb_img.
$thumb_file_size = filesize('C:\\Temp\\temp.jpg');
$fp = fopen('C:\\Temp\\temp.jpg', "rb");
$thumb_data = addslashes (fread ($fp, $thumb_file_size));
fclose ($fp);
unlink('C:\\Temp\\temp.jpg');


This case can be closed then, I hope it will help you to improve again your excellent application!  :P