Page 1 of 1
problem to open files
Posted: Fri Apr 16, 2004 8:38 am
by dizeta
hi

,
i have still problems to complete my news manager script.
well, when i click on a link to open
file1 for the first time , it woks.
but if i try to click to another link ( in the same page) to open a new
file2, will be open always the file1....
any ideas?
the script:
Code: Select all
<?php
include("dbconnect.php");
$query = mysql_query("SELECT id_sharepdf, DatiBinari, nome, Type, news.id_news FROM pdf, news WHERE pdf.id_sharepdf = news.id_news")or die(mysql_error());
$result = @mysql_fetch_assoc($query);
header("Content-Type: {$result['Type']}");
header("Content-Disposition: filename={$result['Nome']}");
header("Content-Transfer-Encoding: binary");
echo $result['DatiBinari'];
@mysql_close();
?>
thanks
Posted: Fri Apr 16, 2004 9:42 am
by JAM
Tricky... Lookup header() and check if adding cache-headers helps in this case. Ie. but not limited to the following:
Code: Select all
header("Pragma: public");
header("Expires: 0"); // set expiration time
header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
Posted: Fri Apr 16, 2004 10:29 am
by dizeta
JAM wrote:Tricky... Lookup header() and check if adding cache-headers helps in this case. Ie. but not limited to the following:
Code: Select all
header("Pragma: public");
header("Expires: 0"); // set expiration time
header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
same problems....
Code: Select all
<?php
header("Content-Type: {$result['Type']}");
header("Content-Disposition: filename={$result['Nome']}");
header("Content-Transfer-Encoding: binary");
header("Pragma: public");
header("Expires: 10"); // set expiration time
header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
?>
Posted: Sat Apr 17, 2004 3:17 am
by dizeta
help!

Posted: Sat Apr 17, 2004 4:23 am
by JAM
After a second review:
Code: Select all
"SELECT id_sharepdf, DatiBinari, nome, Type, news.id_news FROM pdf, news WHERE pdf.id_sharepdf = news.id_news"
How do you select the two files? The query itself looks like a one-file selection imho.
Ie.: nome is allways the same using only the above. Just making sure that you actually have a way to distinguish between the two files...
Posted: Mon Apr 19, 2004 4:42 am
by dizeta
hi,
i've tried to do this:
Code: Select all
<?
include("dbconnect.php");
$getnews = mysql_query("select * from news ORDER BY id_news DESC")or die (mysql_error());
$query = mysql_query("SELECT pdf.Nome, pdf.id_pdf, news.id_news FROM pdf, news WHERE news.id_news = pdf.id_sharepdf ORDER BY id_news DESC")or die (mysql_error());
$query2 = mysql_query("SELECT doc.Nome, doc.id_doc, news.id_news FROM doc, news WHERE news.id_news = doc.id_sharedoc ORDER BY id_news DESC")or die (mysql_error());
while ($row = mysql_fetch_array($getnews))
{
$nome=mysql_fetch_assoc($query);
$nome1=mysql_fetch_assoc($query2);
extract($row);
echo <<< NEWS
<div id="riga"><h3>Titolo: $title</h3></div>
<div id="riga1"=><h4>News inserita il $date - <b>Autore:</b> $author</h4></div>
<div id="riga2"><h5>$news</h5>
<img src="../../../immagini/pdf.gif" width="16" height="16" style="float: left;" />
[b]<a href="download.php?action=download&type=pdf&Id={$nome['id_pdf']}"/><h6>{$nome['Nome']}</h6></a>[/b]
<img src="../../../immagini/word.gif" width="16" height="16" style="float: left;" />
[b]<a href="download.php?action=download&type=doc&Id={$nome1['id_doc']}"/><h6>{$nome1['Nome']}</h6></a>[/b]</div>
<div id="riga3"></div>
NEWS;
}
?>
and download.php ( to openthe news with Reader and/or Word)
Code: Select all
<?php
include("dbconnect.php");
$query = false;
switch($_GET['type']) {
case 'pdf':
$query = "SELECT DatiBinari, Nome, Type, news.id_news FROM pdf, news WHERE pdf.id_sharepdf = '{$_GET['id_pdf']}'";
break;
case 'doc':
$query = "SELECT DatiBinari, Nome, Type, news.id_news FROM doc, news WHERE doc.id_sharedoc = '{$_GET['id_doc']}'";
break;
default:
echo "Dati non corretti";
break;
}
if($query !== false) {
$result = mysql_query($query) or die(mysql_error());
list($DatiBinari, $Nome, $Type, $id_news) = mysql_fetch_row($result);
header("Content-Type: {$result['Type']}");
header("Content-Disposition: filename={$result['Nome']}");
header("Content-Transfer-Encoding: binary");
//header("Pragma: public");
//header("Expires: 10"); // set expiration time
//header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
echo $DatiBinari;
}
?>
but now it returns a blank page

....
[Edit: Added more PHP tags for eyecandy. --JAM]
Posted: Mon Apr 19, 2004 1:22 pm
by dizeta
up

Posted: Mon Apr 19, 2004 1:32 pm
by liljester
i was having some troubles with downloading files in IE (pdf), i dunno if your still having header troubles, but i can tell you that these are the headers i sent, and pdf will open correctly with them:
Code: Select all
header("Content-Type: application/octetstream");
header("Expires: ". gmdate("D, d M Y H:i:s") . " GMT");
header("Content-Disposition: inline; filename="$_POST[file_name]"");
header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
header("Pragma: public");
Posted: Mon Apr 19, 2004 1:36 pm
by JAM
Because...
Code: Select all
<a href="download.php?action=download&type=doc&Id={$nome1['id_doc']}"/>
You are using Id= is those links, but {$_GET['id_doc']} in the download.php?
Sidenote; I
think that:
Code: Select all
header("Content-Transfer-Encoding: binary");
// should be
header("Content-Transfer-Encoding: inline");
Posted: Mon Apr 19, 2004 2:04 pm
by dizeta
JAM wrote:Because...
Code: Select all
<a href="download.php?action=download&type=doc&Id={$nome1['id_doc']}"/>
You are using Id= is those links, but {$_GET['id_doc']} in the download.php?
i'm sorry...but i'm not sure to understand what you're telling me...
could you explain me?
thanks for the patience
Posted: Mon Apr 19, 2004 3:39 pm
by JAM
If you use a link that looks like this,
Code: Select all
<a href="download.php?action=download&type=doc&Id=FOO" />
...you need to use $_GET['Id'] to retrieve the value FOO.
Now look at your script. You use $_GET['id_doc'] in your SQL query, but you do not have that in the URI/link ( no id_doc= ).
Hope I explained abit better this time.
Posted: Tue Apr 20, 2004 1:34 pm
by dizeta
ok, now all scripts work
the solution was:
news.php:
Code: Select all
<?php
include("dbconnect.php");
$query = "SELECT news.id_news, news.author, news.date, news.title, news.news, pdf.id_pdf, pdf.Nome, doc.id_doc, doc.Nome
FROM news
LEFT JOIN pdf ON (news.id_news = pdf.id_sharepdf)
LEFT JOIN doc ON (news.id_news = doc.id_sharedoc)";
$result = mysql_query($query) or die(mysql_error());
while(list($id_news, $author, $date, $title, $news, $id_pdf, $nome_pdf, $id_doc, $nome_doc) = mysql_fetch_row($result)) {
echo "
<div id="riga"><h3>Titolo: $title</h3></div>
<div id="riga1"=><h4>News inserita il $date - <b>Autore:</b> $author</h4></div>
<div id="riga2"><h5>$news</h5>
<img src="../../../immagini/pdf.gif" width="16" height="16" style="float: left;" />
<a href="download.php?action=download&type=pdf&Id=$id_news"/><h6>$nome_pdf</h6></a>
<img src="../../../immagini/word.gif" width="16" height="16" style="float: left;" />
<a href="download.php?action=download&type=doc&Id=$id_news"><h6>$nome_doc</h6></a>
</div>";
}
?>
and for
download.php:
Code: Select all
<?php
include("dbconnect.php");
switch($_GET['type']) {
case 'pdf':
$query = "SELECT DatiBinari, Nome, Type FROM pdf WHERE id_sharepdf = '{$_GET['Id']}'";
break;
case 'doc':
$query = "SELECT DatiBinari, Nome, Type FROM doc WHERE id_sharedoc = '{$_GET['Id']}'";
break;
default:
echo "Dati non corretti";
exit;
break;
}
$result = mysql_query($query) or die(mysql_error());
if($result) {
$ris = mysql_fetch_assoc($result);
header("Content-Type: {$ris['Type']}");
header("Expires: ". gmdate("D, d M Y H:i:s") . " GMT");
header("Content-Disposition: inline; filename={$ris['Nome']}");
header("Content-Transfer-Encoding: inline");
header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
header("Pragma: public");
echo $ris['DatiBinari'];
exit;
}
?>
but i still have a little and annoiyng problem.
when i open a doc file from browser (IE), MS Word ask me in a little windows to "convert file from:" with a list of applications inside.
it's a header's problem? how can i solve this problem?
thanks