Welcome to the GoFuckYourself.com - Adult Webmaster Forum forums.

You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community you will have access to post topics, communicate privately with other members (PM), respond to polls, upload content and access many other special features. Registration is fast, simple and absolutely free so please, join our community today!

If you have any problems with the registration process or your account login, please contact us.

Post New Thread Reply

Register GFY Rules Calendar
Go Back   GoFuckYourself.com - Adult Webmaster Forum > >
Discuss what's fucking going on, and which programs are best and worst. One-time "program" announcements from "established" webmasters are allowed.

 
Thread Tools
Old 07-15-2006, 07:29 AM   #1
qw12er
Confirmed User
 
Join Date: Apr 2004
Location: Montreal
Posts: 799
:stoned PHP Gurus

I'm using this function to send a file to my users :

function send_file($name) {
ob_end_clean();
$path = $name;

if (!is_file($path) or connection_status()!=0) return(FALSE);
header("Cache-Control: no-store, no-cache, must-revalidate");
header("Cache-Control: post-check=0, pre-check=0", false);
header("Pragma: no-cache");
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-Type: application/octet-stream");
header("Content-Length: ".(string)(filesize($path)));
header("Content-Disposition: inline; filename=$name");
header("Content-Transfer-Encoding: binary\n");

if ($file = fopen($path, 'rb')) {
while(!feof($file) and (connection_status()= =0)) {
print(fread($file, 1024*8));
ob_flush();
}
fclose($file);
}
return((connection_status()= =0) and !connection_aborted());
}


But for some reason if I try to open it without saving it on my disk it will causes an error. (Invalid Zip file) But if I save the file first and then open it everything works just fine.

How can I fix that ?
__________________
I have nothing to advertise ... yet.
qw12er is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 07-15-2006, 07:33 AM   #2
Damian_Maxcash
So Fucking Banned
 
Join Date: Oct 2002
Location: MaxCash.com
Posts: 12,745
Quote:
Originally Posted by qw12er
I'm using this function to send a file to my users :

function send_file($name) {
ob_end_clean();
$path = $name;

if (!is_file($path) or connection_status()!=0) return(FALSE);
header("Cache-Control: no-store, no-cache, must-revalidate");
header("Cache-Control: post-check=0, pre-check=0", false);
header("Pragma: no-cache");
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-Type: application/octet-stream");
header("Content-Length: ".(string)(filesize($path)));
header("Content-Disposition: inline; filename=$name");
header("Content-Transfer-Encoding: binary\n");

if ($file = fopen($path, 'rb')) {
while(!feof($file) and (connection_status()= =0)) {
print(fread($file, 1024*8));
ob_flush();
}
fclose($file);
}
return((connection_status()= =0) and !connection_aborted());
}


But for some reason if I try to open it without saving it on my disk it will causes an error. (Invalid Zip file) But if I save the file first and then open it everything works just fine.

How can I fix that ?

Im not totally sure - but I think it could be the mime type setting in your apache config file that is the issue. That could be a start for you to Google from - but I could be way off.
Damian_Maxcash is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 07-15-2006, 07:36 AM   #3
StuartD
Sofa King Band
 
StuartD's Avatar
 
Join Date: Jul 2002
Location: Outside the box
Posts: 29,903
Quote:
Originally Posted by qw12er
header("Content-Type: application/octet-stream");
Try changing this to

header("Content-Type: application/zip");

A list of other content types can be found just over half way down the page here:
http://www.expertsrt.com/tutorials/M...P_headers.html
StuartD is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 07-15-2006, 07:55 AM   #4
qw12er
Confirmed User
 
Join Date: Apr 2004
Location: Montreal
Posts: 799
Was a nice Idea but it doesn't works either :-(
__________________
I have nothing to advertise ... yet.
qw12er is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 07-15-2006, 07:57 AM   #5
Ace_luffy
www.creationcrew.com
 
Ace_luffy's Avatar
 
Industry Role:
Join Date: Feb 2005
Location: CREATIONCREW.COM CREATIONCREW.COM CREATIONCREW.COM CREATIONCREW.COM CREATIONCREW.COM CREATIONCREW.COM
Posts: 12,111
bump.....
__________________


++ Adult and Mainstream Websites Designs | 10 banners for only $50 | html5 Banners ++
email : [email protected] Telegram : https://t.me/creationcrew | HTML5/Responsive Site - Div/CSS - ElevatedX - NATs - Wordpress

Ace_luffy is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 07-15-2006, 09:09 AM   #6
duckduckgoose
Registered User
 
Industry Role:
Join Date: Mar 2006
Location: North Pole
Posts: 82
If I open a zip file when prompted by my browser during testing (rather than save it), it opens fine for me (using WinRAR as my archiver on my pc here). The same zip file also opens fine if I actually save it to disk when prompted by the browser. This is using Firefox v1.5.0.4. The code does not work properly at all for me in IE6, but rather gives a browser error after trying to send the page (whatever.php where your function is sitting) itself.

My guess is that your specific combination of headers used so as not to cache the file being downloaded are the problem for you. You're telling the browser not to cache a copy of the file, which is fine if you're saving it to disk locally. However, if you try and have the browser just open the file without having cached it, it will probably choke depending on browser behaviour. There are varying combinations of http headers you can use in your PHP scripts to avoid having files be cached on the local browser; some of them are browser specific (IE one way, most other browsers another way), so on past scripts i can remember doing a check for IE before sending appropriate headers for tools like yours.

Read through the PHP documentation on headers for more info :
http://ca3.php.net/header
__________________
rRhino.com ...social networking for book fans...
duckduckgoose is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 07-15-2006, 11:00 AM   #7
qw12er
Confirmed User
 
Join Date: Apr 2004
Location: Montreal
Posts: 799
Your right ! it seems to works fine with FireFox.

It try a lot of cache-related header but I can't seem to get IE to works. I just don't get it !
__________________
I have nothing to advertise ... yet.
qw12er is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 07-15-2006, 11:06 AM   #8
mrthumbs
salad tossing sig guy
 
mrthumbs's Avatar
 
Join Date: Apr 2002
Location: mrthumbs*gmail.com
Posts: 11,702
why not a simple redirect to a physical file location?
mrthumbs is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 07-15-2006, 11:19 AM   #9
qw12er
Confirmed User
 
Join Date: Apr 2004
Location: Montreal
Posts: 799
Quote:
Originally Posted by mrthumbs
why not a simple redirect to a physical file location?
because I want to delete the file as soon as it has been downloaded.
Impossible to do if you redirect to the file...
__________________
I have nothing to advertise ... yet.
qw12er is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 07-15-2006, 11:21 AM   #10
Big_Red
Confirmed User
 
Join Date: Jun 2006
Location: Do you care?
Posts: 4,147
bump. php pro's time to step up! good luck qw12er.
__________________
60% Revshare.
http://www.boobycash.com We got the boobs and the cash!
ICQ 198-580-197 24/7 support
Big_Red is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 07-15-2006, 01:37 PM   #11
qw12er
Confirmed User
 
Join Date: Apr 2004
Location: Montreal
Posts: 799
thanks for all the bump.

bump for myself :-)
__________________
I have nothing to advertise ... yet.
qw12er is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 07-15-2006, 06:37 PM   #12
qw12er
Confirmed User
 
Join Date: Apr 2004
Location: Montreal
Posts: 799
bump
5678
__________________
I have nothing to advertise ... yet.
qw12er is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 07-16-2006, 07:24 AM   #13
qw12er
Confirmed User
 
Join Date: Apr 2004
Location: Montreal
Posts: 799
Sorry to bump this an other time but I realy need a solution :-(
__________________
I have nothing to advertise ... yet.
qw12er is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 07-16-2006, 07:47 AM   #14
Damian_Maxcash
So Fucking Banned
 
Join Date: Oct 2002
Location: MaxCash.com
Posts: 12,745
Quote:
Originally Posted by qw12er
Sorry to bump this an other time but I realy need a solution :-(
Did you check out the mime type thing?

The more I think about it the I think that is the issue.

If you dont have access to your Apache configs then try this in a .htaccess file

AddType zip file zip
Damian_Maxcash is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 07-16-2006, 01:25 PM   #15
BigBen
Confirmed User
 
Join Date: Nov 2004
Location: scv
Posts: 2,299
Quote:
Originally Posted by qw12er
Sorry to bump this an other time but I realy need a solution :-(
Try the forums at devshed or webmasterworld.
BigBen is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 07-16-2006, 05:04 PM   #16
duckduckgoose
Registered User
 
Industry Role:
Join Date: Mar 2006
Location: North Pole
Posts: 82
If you replace all of the header() lines you used with the following ones, it works correctly in IE6 and Firefox.

header('Cache-Control: ');
header('Pragma: ');
header("Content-Type: application/force-download");
header("Content-length: " . (string)(filesize($path)));
header("Content-Disposition: attachment; filename=" . $path);


Test it yourself and see how it works out for you.
__________________
rRhino.com ...social networking for book fans...

Last edited by duckduckgoose; 07-16-2006 at 05:05 PM..
duckduckgoose is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 07-16-2006, 07:30 PM   #17
qw12er
Confirmed User
 
Join Date: Apr 2004
Location: Montreal
Posts: 799
I don't understand why but it does works !!!

Thanks DuckDuckGoose.
__________________
I have nothing to advertise ... yet.
qw12er is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Post New Thread Reply
Go Back   GoFuckYourself.com - Adult Webmaster Forum > >

Bookmarks



Advertising inquiries - marketing at gfy dot com

Contact Admin - Advertise - GFY Rules - Top

©2000-, AI Media Network Inc



Powered by vBulletin
Copyright © 2000- Jelsoft Enterprises Limited.