Page 1 of 2
problem with download files
Posted: Thu Oct 27, 2005 8:15 am
by dizeta
hi,
i have a problem with download files:
Code: Select all
<a href=\"actions.php?action=download&id={$result["id_manu"]}\">download</a>
this querystring works well, i can download the file and i can open it correctly.
this one:
Code: Select all
<a href=\"index.php?page=auth/actions&action=download&id={$result["id_manu"]}\">download</a>
it doesn't work, i can' t open fdf or doc files...why??
actions.php is the same file in 2 different directories.
i tried to print the $vars that i send from download page to actions.php.
first one ( works )
Code: Select all
Array
(
[action] => download
[id] => 9
[uid] => 9445687aeb726ab3fb8d2e5ebd44f9ee
)
second one ( doesn't work )
Code: Select all
Array
(
[page] => auth/actions
[action] => download
[id] => 9
[uid] => 9445687aeb726ab3fb8d2e5ebd44f9ee
)
as you can see, no differences

Posted: Thu Oct 27, 2005 8:17 am
by Jenk
I can see a difference... there is a 'page' indice on the second one..
And it'll be the '/' in "auth/actions" causing you grief.
Posted: Thu Oct 27, 2005 8:18 am
by Chris Corbyn
Perhaps if you post the code that handles the download

Posted: Thu Oct 27, 2005 8:24 am
by dizeta
Code: Select all
if(!isset($_GET)) $_GET = $HTTP_GET_VARS;
if($_GET["action"] && $_GET["id"] && is_numeric($_GET["id"])) {
include("dbconnect");
switch($_GET["action"]) {
case "view" :
$query = "SELECT * FROM manuali WHERE id_manu = '" . $_GET["id"] . "'";
$select = @mysql_query($query) or die("Failure !");
$result = @mysql_fetch_array($select);
$data = $result["bin_data"];
$type = $result["filetype"];
Header("Content-type: $type");
echo $data;
break;
// DOWNLOAD
case "download" :
$query = "SELECT * FROM manuali WHERE id_manu = '" . $_GET["id"] . "'";
$select = @mysql_query($query) or die("Failure !");
$result = @mysql_fetch_array($select);
$data = $result["bin_data"];
$name = $result["filename"];
$type = $result["filetype"];
// INTERNET EXPLORER
if(ereg("MSIE ([0-9].[0-9]{1,2})", $_SERVER["HTTP_USER_AGENT"])) {
header("Content-Type: application/octetstream");
header("Content-Disposition: inline; filename=$name");
header("Expires: 0");
header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
header("Pragma: public");
} else {
header("Content-Type: application/octet-stream");
header("Content-Disposition: attachment; filename=$name");
header("Expires: 0");
header("Pragma: no-cache");
}
echo $data;
break;
default :
// DEFAULT CASE, NO ACTIONS
break;
} // endswitch
@mysql_close();
} //endif
And it'll be the '/' in "auth/actions" causing you grief.
sorry, what i have to do?

Posted: Thu Oct 27, 2005 8:46 am
by Grim...
<!-- Ignore me -->
Posted: Thu Oct 27, 2005 10:25 am
by Chris Corbyn
Hmmm.... I can't see anything obvious and I doubt that it is the "/" that's the issue but just in case try replacing the "/" in the URL with "%2F".
urlencode() could do that for you

Not sure if it'll make a difference.
Posted: Thu Oct 27, 2005 11:03 am
by dizeta
i've tried with urlencode
Code: Select all
$path = "auth/actions";
<a href=\"index.php?page=".urlencode($path)."&action=download&id={$result["id_manu"]}\">download</a>
but no changes...
well, maybe i've forgot to tell you that download works, but i can't open the file doc or pdf.
the file results corrupt...

Posted: Thu Oct 27, 2005 12:00 pm
by Chris Corbyn
Just a thought, but try stripslashes($data) on the download part.... maybe it's got backslashes in that shouldn't be there

Posted: Thu Oct 27, 2005 2:31 pm
by dizeta

no changes again
i've tried to print the .doc inside the page
Code: Select all
echo "<p style=\"color:blue\">".stripslashes($data)."</p><br />";
but still results corrupt
this is a big problem for me...

Posted: Thu Oct 27, 2005 2:36 pm
by feyd
why are you trying to show either type of file inside a page? They are both binary formats and not intended to be displayed in such a manor. Simply send the file with
readfile() with the correct
headers
Posted: Thu Oct 27, 2005 2:54 pm
by dizeta
hi,
ok, it was just a test...
correct headers?
the scripts with headers that i've posted are not correct?
as i've posted at beginning of this post, my problem is download files with :
<a href=\"index.php?page=auth/actions&action=download
the other querystring
<a href=\"actions.php?action=download
works correctly ( with the same headers, same file)
Posted: Thu Oct 27, 2005 2:58 pm
by feyd
url encode the keys and values for each key-value pair used in the query string.
Posted: Thu Oct 27, 2005 3:41 pm
by dizeta
feyd,
you mean something like this?
Code: Select all
$path = "page=auth/actions";
$path1 = "action=download";
$path2 = "id={$result['id_manu']}";
<a href=\"index.php?".urlencode($path)."&".urlencode($path1)."&".urlencode($path2)."\">download</a>
if yes, when i click on download link, i'm redirect to the homepage. download doesn't start, i don't receive nothing to the control script ( action ).....
Posted: Thu Oct 27, 2005 3:57 pm
by feyd
sort-of... encode the key separate from the value, then attach each pair together like normal (equal sign) then attach all the parameters together like normal (ampersand)
Posted: Thu Oct 27, 2005 4:44 pm
by dizeta
ok, feyd
I hope to have understood, if not i'm sorry..
Code: Select all
$path = "page";
$path1 = "auth/actions";
$path2 = "action";
$path3 = "download";
$path4 = "id";
$path5 = "{$result['id_manu']}";
<a href=\"index.php?".urlencode($path)."=".urlencode($path1)."&".urlencode($path2)."=".urlencode($path3)."&".urlencode($path4)."=".urlencode($path5)."\">download</a>
same problem...