Current location: Hot Scripts Forums » Programming Languages » PHP » File downloads corrupt?


File downloads corrupt?

Reply
  #1 (permalink)  
Old 07-12-05, 05:10 PM
FiRe FiRe is offline
Code Guru
 
Join Date: Oct 2004
Location: UK
Posts: 801
Thanks: 0
Thanked 0 Times in 0 Posts
File downloads corrupt?

PHP Code:

<?php

session_start
();
error_reporting(0);

//Get session data
$s $_SESSION['blah'];

//Apply decryption algorithm
include("class.php");
$rc4 = new rc4crypt;
$ss $rc4->endecrypt($key$s'de');
$explode explode("|"$ss);
$tmp trim($explode[0]);
$actual trim($explode[1]);

//Get extension
$File_Extension substr(strrchr($actual"."), 1);

//Get content type
switch ($File_Extension) {
case 
'jpg':
$type 'image/jpeg';
break;
case 
'jpeg':
$type 'image/jpeg';
break;
case 
'gif':
$type 'image/gif';
break;
case 
'png':
$type 'image/x-png';
break;
case 
'bmp':
$type 'image/x-ms-bmp';
break;
case 
'zip':
$type 'application/zip';
break;
case 
'rar':
$type 'application/unknown';
break;
case 
'tar':
$type 'application/x-tar';
break;
case 
'gtar':
$type 'application/x-gtar';
break;
case 
'doc':
$type 'application/msword';
break;
case 
'xls':
$type 'application/vnd.ms-excel';
break;
case 
'txt':
$type 'text/plain';
break;
case 
'pdf':
$type 'application/pdf';
break;
}

//Set headers
header('Content-type: '.$type.'');
header('Content-Disposition: attachment; filename="files/'.$tmp.'"');
readfile(''.$actual.'');

//Finish off
session_destroy();
error_reporting(2039);
?>
For some reason IE says the file will download as an HTML file when in fact its an image file which is corrupt I think I have get the code in the wrong places, can anyone help me clear this up?
__________________
Alexa Share <-- Trade virtual shares in websites with this online game.

codR.us <-- Submit and vote for your favorite code snippets with codR.us.

XEWeb.net <-- The ultimate PHP resource network.
Reply With Quote
  #2 (permalink)  
Old 07-13-05, 02:46 AM
dennispopel dennispopel is offline
Coding Addict
 
Join Date: Mar 2005
Posts: 263
Thanks: 0
Thanked 0 Times in 0 Posts
Hello,

I suggest you first debug the value of the $tmp variable; I believe it contains only file name without the extension. Also check this script with other browsers. Besides, I don't think it's a good idea to have filename="files/myfile" in the Content-Disposition: header.
__________________
onPHP5.com - PHP5: Articles, News, Tutorials, Interviews, Software and more
Reply With Quote
  #3 (permalink)  
Old 07-13-05, 02:02 PM
FiRe FiRe is offline
Code Guru
 
Join Date: Oct 2004
Location: UK
Posts: 801
Thanks: 0
Thanked 0 Times in 0 Posts
tested it and the session works out fine when decrypted :|
also files/ is the directory it is stored in!

if the session contained this data decrypted:
PHP Code:

abc123.gif|smiley.gif 

then the headers should look like this:
PHP Code:

header('Content-type: image/gif'); 

header('Content-Disposition: attachment; filename="files/abc123.gif"'); 
readfile('smiley.gif'); 
any help?
__________________
Alexa Share <-- Trade virtual shares in websites with this online game.

codR.us <-- Submit and vote for your favorite code snippets with codR.us.

XEWeb.net <-- The ultimate PHP resource network.
Reply With Quote
  #4 (permalink)  
Old 07-14-05, 08:24 AM
dennispopel dennispopel is offline
Coding Addict
 
Join Date: Mar 2005
Posts: 263
Thanks: 0
Thanked 0 Times in 0 Posts
Hmm... still try remove the 'files/' form the filename in header
__________________
onPHP5.com - PHP5: Articles, News, Tutorials, Interviews, Software and more
Reply With Quote
  #5 (permalink)  
Old 07-14-05, 08:45 AM
FiRe FiRe is offline
Code Guru
 
Join Date: Oct 2004
Location: UK
Posts: 801
Thanks: 0
Thanked 0 Times in 0 Posts
but then the file will not be valid as it wont know where to look!

should i try changing it to the file path instead?
__________________
Alexa Share <-- Trade virtual shares in websites with this online game.

codR.us <-- Submit and vote for your favorite code snippets with codR.us.

XEWeb.net <-- The ultimate PHP resource network.
Reply With Quote
Reply

Bookmarks

« Page Expire | Forms »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

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

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Initiate file downloads without link paths? RickW Perl 1 03-15-05 08:02 AM
File Downloads mkmagu HTML/XHTML/XML 3 04-01-04 08:28 PM
Using PHP to allow access to file downloads after user pays jmcclin2 PHP 2 03-11-04 09:28 AM
Getting the created file (fopen/fwrite) Programme PHP 5 02-14-04 03:09 PM
Downloads a txt file and print perleo PHP 4 11-21-03 10:58 AM


All times are GMT -5. The time now is 06:55 AM.
vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.