PHP Coding
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Codewalkers ForumsPHP RelatedPHP Coding

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Codewalkers Forums Sponsor:
  #1  
Old October 3rd, 2002, 03:04 PM
mrq mrq is offline
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Apr 2007
Posts: 37 mrq User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 3
problem downloading JPEG image

Oki i have a problem that after downloading JPEG image through my download script the Adobe Photoshop can open it and says: "Could not open the document because a JPEG marker segment length is too short (the file
may be truncated or incomplete)."? What can be wrong?
Script is like that! NB! the downloading is working great except that the JPEG image is rotten!!
<?php
////////////////////////////////////////////////////////////////////
//SKRIPTI:download 1.1, //
//e-mail:mrq@themail.com //
//Greated: 04.04.2002 //
// //
////////////////////////////////////////////////////////////////////
require("incl/register.php");
if($HTTP_REFERER=="http://www.mfa.ee:83/gallery//download.php"){
echo"First you have to register and then download!";
exit;
}
if(isset($id)){
require"incl/mysql.php";
$select = "SELECT klient_pildid.pildi_id,pildid.pilt,pildid.pealkiri ,pildid.valja FROM pildid,klient_pildid WHERE pildid.id=$id AND klient_pildid.klient_id='$HTTP_GET_VARS[k]'";
$valjasta = mysql_query($select) or die("Lause on vigane");
while(list($id,$pilt,$pealkiri,$valja) = mysql_fetch_row($valjasta)){
echo $id;
echo"<br>";
if($valja==1){
$fileDir="temp2434";
$completeFilePath=$fileDir.'/'.$pilt;
if(strpos($HTTP_SERVER_VARS['HTTP_USER_AGENT'], 'MSIE')){
// IE cannot download from sessions without a cache
header('Cache-Control: public');
}else{
//header("Cache-Control: no-cache, must-revalidate");
header("Cache-Control: no-cache");
}
header("Pragma: no-cache");
header("Content-Type: image/jpegn");
header ("Connection: close");
header("Content-Disposition: attachment; filename="$pealkiri"n");
header("Content-Transfer-Encoding: binaryn");
header("Content-length: ".(string)(filesize($completeFilePath)));
$fd=fopen("$completeFilePath","rb");
fpassthru($fd);
exit;
}else{
Header("location:$HTTP_REFERER");
}
}
mysql_close();
}
?>

Reply With Quote
  #2  
Old October 3rd, 2002, 03:36 PM
Anonymous Anonymous is offline
Registered User
Codewalkers God 35th Plane (22000 - 22499 posts)
 
Join Date: Apr 2007
Posts: 22,309 Anonymous User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 25
RE: problem downloading JPEG image

Try using:

while(!feof($fd)) {
print fread($fd, 4096);
}
fclose($fd);

in place for the fpassthru..


Reply With Quote
  #3  
Old October 3rd, 2002, 03:44 PM
mrq mrq is offline
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Apr 2007
Posts: 37 mrq User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 3
RE: problem downloading JPEG image

nop did'nt work either!

Mb something else. If some1 could test this script or something like that then look does the jpeg image remain the same or again will be rotten then i know that the error is not only me or counterwise!

Reply With Quote
  #4  
Old October 3rd, 2002, 03:53 PM
Matt Matt is offline
Contributing User
Codewalkers Specialist (4000 - 4499 posts)
 
Join Date: Apr 2007
Location: Florida
Posts: 4,158 Matt User rank is Private First Class (20 - 50 Reputation Level)Matt User rank is Private First Class (20 - 50 Reputation Level) 
Time spent in forums: 4 h 12 m 16 sec
Reputation Power: 7
RE: problem downloading JPEG image

php Code:
Original - php Code
  1. <?
  2. if(strpos($HTTP_SERVER_VARS['HTTP_USER_AGENT'], 'MSIE')){
  3.   // IE cannot download from sessions without a cache
  4.   header('Cache-Control: public');
  5. }else{
  6.   //header("Cache-Control: no-cache, must-revalidate");
  7.   header("Cache-Control: no-cache");
  8. }
  9. header("Pragma: no-cache");
  10. header("Content-Type: image/jpegn");
  11. header ("Connection: close");
  12. header("Content-Disposition: attachment; filename="test.jpg"n");
  13. header("Content-Transfer-Encoding: binaryn");
  14. header("Content-length: ".(string)(filesize("test.jpg")));
  15. $fd=fopen("test.jpg","rb");
  16. fpassthru($fd);
  17. ?>


I used that script to test, which is basically your script without the database parts and it works! So maybe something you are pulling from the database is wrong?

Try running the above script with a test.jpg file in the same dir and see if it works right...

Reply With Quote
  #5  
Old October 4th, 2002, 06:58 AM
mrq mrq is offline
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Apr 2007
Posts: 37 mrq User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 3
RE: problem downloading JPEG image

Oki i got it working . So happy!
Thx to Matt
The code is below
php Code:
Original - php Code
  1.  
  2. <?php
  3. //////////////////////////////////                                 
  4. //Script name: download 1.2     //
  5. //E-mail:mrq@themail.com        //
  6. //Greated: 04.04.2002           //
  7. //////////////////////////////////                                 
  8. require("incl/register.php");
  9. if($HTTP_REFERER=="http://www.mfa.ee:83/gallery//download.php"){
  10.         echo"First you have to register and then download!";
  11.         exit;
  12. }
  13. if(isset($id)){
  14.         require"incl/mysql.php";
  15.         $select = "SELECT klient_pildid.pildi_id,pildid.pilt,pildid.pealkiri  ,pildid.valja FROM pildid,klient_pildid WHERE pildid.id=$id AND klient_pildid.klient_id='$HTTP_GET_VARS[k]'";
  16.         $valjasta = mysql_query($select) or die("The query is incorrect");
  17.         while(list($id,$pilt,$pealkiri,$valja) = mysql_fetch_row($valjasta)){
  18.                 if($valja==1){
  19.                 $fileDir="secret";//secret directory :)
  20.                 $completeFilePath=$fileDir.'/'.$pilt;
  21.                 if(strpos($HTTP_SERVER_VARS['HTTP_USER_AGENT'], 'MSIE')){
  22.                         // IE cannot download from sessions without a cache
  23.                         header('Cache-Control: public');
  24.                 }else{
  25.                         //header("Cache-Control: no-cache, must-revalidate");
  26.                         header("Cache-Control: no-cache");
  27.                 }
  28.                 header("Pragma: no-cache");
  29.                 header("Content-Type: image/jpegn");
  30.                 //header("Connection: close");
  31.                 header("Content-Disposition: attachment; filename="$pealkiri.JPG"n");
  32.                 header("Content-Transfer-Encoding: binaryn");
  33.                 header("Content-length: ".(string)(filesize($completeFilePath)));
  34.                 $fd=fopen("$completeFilePath","rb");
  35.                 fpassthru($fd);
  36.                 exit;
  37.                 }else{
  38.                         Header("location:$HTTP_REFERER");
  39.                 }
  40.         }
  41. }
  42. ?>

Reply With Quote
  #6  
Old October 4th, 2002, 07:02 AM
mrq mrq is offline
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Apr 2007
Posts: 37 mrq User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 3
RE: problem downloading JPEG image

The problem was that before the fpassthru i printed out some info:
php Code:
Original - php Code
  1.  
  2. while(list($id,$pilt,$pealkiri,$valja) = mysql_fetch_row($valjasta)){
  3. echo $id;//wrong place in a wrong time
  4. echo"<br>";//wrong place in a wrong time
  5. if($valja==1){

Reply With Quote
Reply

Viewing: Codewalkers ForumsPHP RelatedPHP Coding > problem downloading JPEG image


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump




 Free IT White Papers!
 
Create the Optimal Architecture for your Critical Applications
Warburton's the largest independently owned bakery in the UK faced a number of difficult challenges in providing the most robust yet efficient IT infrastructure for their organization's success. IBM's services combined with their xSeries servers created the perfect platform for their SAP environment with sufficient flexibility, and did so in very time effective fashion.

Request Your Free Technology Downloads!
 
Five Best Practices for Deploying a Successful Service-Oriented Architecture
This white paper describes the benefits you can expect with SOA, and how IBM can help take your business there.

Request Your Free Technology Downloads!
 
Gartner Magic Quadrant for Application Delivery Controllers
Gartner summarizes its view on Application Delivery Controllers, evaluates strengths and weaknesses of solutions, and provides Magic Quadrant reporting for a quick comparison across all vendors. Learn from Gartner how you can benefit from an all-in-one device like Citrix NetScaler that delivers the highest levels of availability, performance and security.

Request Your Free Technology Downloads!
 
Knowledge is Power
What you don't know can hurt you, and is likely costing you money and increasing your security risks during an era of scarce resources. This white paper proposes six key strategies that enterprise security managers can use to improve their network defense posture.

Request Your Free Technology Downloads!
 
Rationalizing the Multi-Tool Environment
The rationalized multi-tool approach is flexible, scalable and cost effective. It provides the necessary input to the IT service management business processes. It preserves prior investments in monitoring tools, empowers technologists to select the best tools with which to do their jobs, and enhances effective response to incidents.

Request Your Free Technology Downloads!
 

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 




© 2003-2010 by Developer Shed. All rights reserved. DS Cluster 6 Hosted by Hostway
For more Enterprise Application Development news, visit eWeek