Page 1 of 1

[SOLVED] php header problems, file become unreadable

Posted: Mon Mar 12, 2007 1:53 pm
by benyboi
I have a script which hides the location of a file, but once the file has been downloaded it is unreadable. whereas if i just download without the script it is fine?

anyone know why?

Code: Select all

<?php
$file=$_GET['file'];

$ref=($_SERVER['HTTP_REFERER']);
$valref=substr($ref, 0, 29);

if($valref == "http://www.xxxxx.com/"){



 
$stat=stat('D:/inetpub/www-xxxxx/' . $file . '.avi');

header('Content-Disposition: attachment; filename=' . $file . '.avi');
header('Content-Length: '.$stat[7]);  
readfile('D:/inetpub/www-xxxxx/' . $file . '.avi');

} else {

if($valref == ""){

?>
There is a problem with your referer.<p>
This means your browser has not told us where you got this link from.<p>
Please check <a href="http://www.xxxxx.com/viewforum.php?f=64">help</a> for more info.

<?

} else {

// Your email address
$email = "info@xxxxx.com";

// The subject
$subject="Invalid referer for video download";

// The message
$comment=$ref;

// The message
$emailfrom= "info@xxxxx.com";

mail($email, $subject, $comment, "From: $emailfrom");

?>
Hotlinking? Tut tut.
<p>
We have recorded which website sent you here and will be taking action.
<p>
If this message has been received in error, please goto our <a href="http://www.xxxxx.com/viewforum.php?f=64">help</a> section to find out why.
<?
}
}

?>
thanks

Posted: Mon Mar 12, 2007 2:01 pm
by feyd
Are the file sizes different with and without the script? If so, then you have extraneous characters entering the stream. They may be just prior to the script starting or just after the script finishing. To narrow down where to look you'll need to compare the two files to find the differences.

If you don't know how to check the differences, http://gnuwin32.sourceforge.net/packages/diffutils.htm may be of interest.

Posted: Mon Mar 12, 2007 2:08 pm
by benyboi
thanks, that seeems logical.

when i do find out whats been inserted where, how do i go about removing it?

thanks

Posted: Mon Mar 12, 2007 2:17 pm
by feyd
If it's not extraneous characters at the beginning or end, you'll have to find what is sending output during the course of your script running.

Posted: Mon Mar 12, 2007 2:41 pm
by benyboi
do i maybe need:

header('Content-Type: '.'video/x-msvideo');

thanks

Posted: Mon Mar 12, 2007 2:50 pm
by benyboi
found it, this is gooing at the top of my files:

Code: Select all

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Untitled Document</title>
</head>

<body>

Posted: Mon Mar 12, 2007 3:02 pm
by benyboi
sorted!

all i had to do was remove the

Code: Select all

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 
<html xmlns="http://www.w3.org/1999/xhtml"> 
<head> 
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> 
<title>Untitled Document</title> 
</head> 

<body>
from the top of the php file! thanks for you tips, otherwise i would never have worked it out.