Zubrag.com
May 20, 2012, 11:21:54 pm *
Welcome, Guest. Please login or register.
Did you miss your activation email?

Login with username, password and session length
 
   Home   Help Search Login Register  
Pages: [1]
  Print  
Author Topic: Issues with .docs and .pdfs  (Read 3373 times)
foox
Newbie
*
Posts: 4


« on: July 21, 2007, 02:42:18 pm »

Hi

This script is just what i was looking for and i it's working great except a few things. When i put a .doc on the server and try to download it with the script it seems to get corrupted in some sort of way. When i choose to open it in Microsoft Word after downloading it through the script i get an error message saying that Word needs a converter to open the document. When i download the file by typing it's direct url it works all good so it seems like the script in some way modifies the file.

When i do the same thing with a .pdf file it works without any corruption but when a user is closing the file the application used to open it prompts for saving or cancel. I don't know but maybe this is related somehow.

Im running FreeBSD 5.3-RELEASE and Apache 1.3 and php4.

Does anyone have any ideas how i can solve this?

I am really looking forward to an answer since this script seems to be just what i need Smiley.

Regards
Kristian

Logged
zubrag
Administrator
Hero Member
*****
Posts: 753


WWW
« Reply #1 on: July 23, 2007, 10:06:07 am »

Try chaging (including ending comma)

'doc' => 'application/msword',

to

'doc' => 'application/force-download',

Does it help to resolve .doc files issue?


application used to open it prompts for saving or cancel
is it Acrobat Reader?
Logged
foox
Newbie
*
Posts: 4


« Reply #2 on: July 24, 2007, 03:21:19 am »

Hi and thank you for the reply!

Unfortunately this didn't solve the problem i am having. I am sending you a private message with the link to the original word document and also a link to the download.php script if that could help you help me in any way Smiley. You could still answer here since other people might have the same problem.

I don't know if you have looked at "download center light" but i don't have the same problem with that script. I'd still like to use your script though since it's smaller and open source.

I am using Adobe Acrobat professional 7.0 when i viewed the pdf document.

Regards
Kristian 
Logged
zubrag
Administrator
Hero Member
*****
Posts: 753


WWW
« Reply #3 on: July 24, 2007, 05:14:32 am »

It adds 4 symbols at the beginning (2F 2F 0A 0A). Looks like these are \ + \ + line feed + line feed

Strange. I tried and it downloaded that doc file ok. Could you send me your download.php to try?

Also try changing

header("Content-Disposition: attachment; filename=\"$asfname\"");

to

header("Content-Disposition: attachment; filename=$asfname");

Any luck?
Logged
foox
Newbie
*
Posts: 4


« Reply #4 on: July 24, 2007, 05:39:25 am »

Yea it's working now and the problem wasn't your script.

I added the following code at the beginning of the script to check for a valid session before sending the file:

<?php
session_start();

if (!isset($_SESSION["inloggning"]) || $_SESSION["inloggning"] !== true) {
header("Location: http://url.to.loginpage");
exit;
}
?>

and since the check worked i didn't think it was that piece of code that damaged the script. I also commented out that code in the beginning but it still failed. When i removed it completely from download.php all worked fine so i guess i really have to apologize for not checking this in before hand.

Any idea what's messing up things with that piece of code in the beginning? I would be really neat not to let people type in the direct url to download.php

Regards
Kristian
Logged
zubrag
Administrator
Hero Member
*****
Posts: 753


WWW
« Reply #5 on: July 24, 2007, 05:51:53 am »

Not sure what is causing this. I added your code to the download.php (without additional <?php ?> tags) and it worked ok. Like this:

<?php

session_start();

if (!isset($_SESSION["inloggning"]) || $_SESSION["inloggning"] !== true) {
header("Location: http://url.to.loginpage");
exit;
}

###############################################################
# File Download

...


Note: you could check referrer instead of session in order to allow downloads from your site only. Something like this:

if (strpos($_SERVER['HTTP_REFERER'],'example.com') == false) {
  header("Location: http://url.to.loginpage");
  exit;
}

But in this case it will not check if user is logged in. You could maybe combine these checks. Just a thought.
Logged
foox
Newbie
*
Posts: 4


« Reply #6 on: July 24, 2007, 07:13:28 am »

Thank you very much.

Everything is working now and i am gonna add the check for referrer as well.

Regards
Kristian
Logged
Pages: [1]
  Print  
 
Jump to:  

Powered by SMF 1.1.11 | SMF © 2006-2009, Simple Machines LLC