file upload/download issue

file upload/download issue

am 11.09.2007 14:48:31 von Rafi

Hi,

I developed a website using php5 & mysql5. One of its features is the
ability of users to upload files to the server, and allow other users
to
view these files.

I allow uploading the following file types: doc, pdf, txt, jpg, gif.

My testing was done on two PCs:
- PC1 with WinXP, IE7, OpenOffice
- PC2 with WinXP, IE6, Office XP.

I manage to successfully download and open files on PC1, but I have
a problem on PC2 with IE6, where in the File Download dialog of IE, I
cannot
press Open and successfully open the file, but if I choose Save and
then
open the saved file, it works!

Additional info:
- Mysql is configured to use utf8.
- My PHP pages deliver the correct content type

- I use "SET NAMES utf8" right after opening a db connection.
- Using addslashes on the file content before saving to db, but
no stripslashes are used - with them, nothing works on PC2.
- Note that in the File Download dialog in IE6 and IE7, the filename
is gibberish.
- In Firefox things work fine. Even the file names in the File
Download
dialog show correctly.

I am beginning to run out of ideas, so
any ideas/suggestions will be much appreciated.

RD

Re: file upload/download issue

am 11.09.2007 14:50:34 von Bucky Kaufman

rafi wrote:
> Hi,
>
> I developed a website using php5 & mysql5. One of its features is the
> ability of users to upload files to the server, and allow other users
> to
> view these files.
>
> I allow uploading the following file types: doc, pdf, txt, jpg, gif.
>
> My testing was done on two PCs:
> - PC1 with WinXP, IE7, OpenOffice
> - PC2 with WinXP, IE6, Office XP.
>
> I manage to successfully download and open files on PC1, but I have
> a problem on PC2 with IE6, where in the File Download dialog of IE, I
> cannot
> press Open and successfully open the file, but if I choose Save and
> then
> open the saved file, it works!
>
> Additional info:
> - Mysql is configured to use utf8.
> - My PHP pages deliver the correct content type
>
> - I use "SET NAMES utf8" right after opening a db connection.
> - Using addslashes on the file content before saving to db, but
> no stripslashes are used - with them, nothing works on PC2.
> - Note that in the File Download dialog in IE6 and IE7, the filename
> is gibberish.
> - In Firefox things work fine. Even the file names in the File
> Download
> dialog show correctly.
>
> I am beginning to run out of ideas, so
> any ideas/suggestions will be much appreciated.

Really - nobody can help if you don't post the code.



>
> RD
>

Re: file upload/download issue

am 11.09.2007 15:36:40 von Rafi

Here it is:

// file download.php

session_start();

require_once('db_login.php');
require_once('MDB2.php');

if(isset($_GET['id']))
{
include 'db_open.php'; // opens db conn and does SET NAMES utf8

$id = $_GET['id'];
$query = "SELECT * FROM attachments WHERE attachment_id = '$id'";
$result = $connection->query($query);
if (PEAR::isError($result)) {
die("Could not query the database:
" .
PEAR::errorMessage($result));
}

$result_row = $result->fetchRow(MDB2_FETCHMODE_ASSOC);

$name = $result_row['name'];
$type = $result_row['type'];
$size = $result_row['size'];
$content = $result_row['content'];

//$name = stripslashes($name);
//$content = stripslashes($content);

include 'db_close.php'; // closes db conn

header("Content-type: $type" . "; charset=utf-8");
header("Content-disposition: attachment; filename=\"" . $name .
"\"");
header("Content-length: $size");
echo $content;

exit;
}

require_once('db_login.php');
require_once('header_footer.php');
require_once('dsp_links.php');
require_once('/home/israelf1/php/MDB2.php');

display_page_header();
display_links();
require('dsp_sidebar.php');

include 'db_open.php';

$query = "SELECT attachment_id, name FROM attachments";
$result = $connection->query($query);
if (PEAR::isError($result)) {
die("Could not query the database:
" .
PEAR::errorMessage($result));
}

while ($result_row = $result->fetchRow(MDB2_FETCHMODE_ASSOC)) {
echo '' . $result_row['name'] . '
';
}
include 'db_close.php';

display_page_footer();

?>

// ----------------------------------------------

// file msg_add.php

....
// get 1st attachment
if (!$stop && isset($_FILES['attachment1']['size']) &&
($_FILES['attachment1']['size'] > 0))
{
$attch1 = true;
$fileName1 = $_FILES['attachment1']['name'];
$tmpName1 = $_FILES['attachment1']['tmp_name'];
$fileSize1 = $_FILES['attachment1']['size'];
$fileType1 = $_FILES['attachment1']['type'];

if (!is_valid_file($fileName1, 1)) {
$err_msg = "document must be doc or txt or pdf.";
$stop = true;
}
else {
$fp1 = fopen($tmpName1, 'r');
$content1 = fread($fp1, $fileSize1);
$content1 = addslashes($content1);
fclose($fp1);
if(!get_magic_quotes_gpc())
{
$fileName1 = addslashes($fileName1);
}
}
}

....

if ($attch1) {
$max_aid++;
$attch_id1 = $max_aid; // attachment id

$query = "INSERT INTO attachments VALUES ($attch_id1, '$fileName1',
'$fileType1', '$fileSize1', '$content1')";
$result = $connection->query($query);
if (PEAR::isError($result)) {
$query = "ROLLBACK";
$result1 = $connection->query($query);
die("Database query (ins attachment1) failed:
" .
PEAR::errorMessage($result));
}
}

....

Re: file upload/download issue

am 11.09.2007 15:47:41 von Bucky Kaufman

rafi wrote:
> if (PEAR::isError($result)) {
> die("Could not query the database:
" .
> PEAR::errorMessage($result));

Wow - you totally lose me at PEAR and die. I don't know nuthin about those.

Also - It would be even better if you posted the question AND the code
in the same post. What was the problem again? :)



> }
>
> $result_row = $result->fetchRow(MDB2_FETCHMODE_ASSOC);
>
> $name = $result_row['name'];
> $type = $result_row['type'];
> $size = $result_row['size'];
> $content = $result_row['content'];
>
> //$name = stripslashes($name);
> //$content = stripslashes($content);
>
> include 'db_close.php'; // closes db conn
>
> header("Content-type: $type" . "; charset=utf-8");
> header("Content-disposition: attachment; filename=\"" . $name .
> "\"");
> header("Content-length: $size");
> echo $content;
>
> exit;
> }
>
> require_once('db_login.php');
> require_once('header_footer.php');
> require_once('dsp_links.php');
> require_once('/home/israelf1/php/MDB2.php');
>
> display_page_header();
> display_links();
> require('dsp_sidebar.php');
>
> include 'db_open.php';
>
> $query = "SELECT attachment_id, name FROM attachments";
> $result = $connection->query($query);
> if (PEAR::isError($result)) {
> die("Could not query the database:
" .
> PEAR::errorMessage($result));
> }
>
> while ($result_row = $result->fetchRow(MDB2_FETCHMODE_ASSOC)) {
> echo '' . $result_row['name'] . '
';
> }
> include 'db_close.php';
>
> display_page_footer();
>
> ?>
>
> // ----------------------------------------------
>
> // file msg_add.php
>
> ....
> // get 1st attachment
> if (!$stop && isset($_FILES['attachment1']['size']) &&
> ($_FILES['attachment1']['size'] > 0))
> {
> $attch1 = true;
> $fileName1 = $_FILES['attachment1']['name'];
> $tmpName1 = $_FILES['attachment1']['tmp_name'];
> $fileSize1 = $_FILES['attachment1']['size'];
> $fileType1 = $_FILES['attachment1']['type'];
>
> if (!is_valid_file($fileName1, 1)) {
> $err_msg = "document must be doc or txt or pdf.";
> $stop = true;
> }
> else {
> $fp1 = fopen($tmpName1, 'r');
> $content1 = fread($fp1, $fileSize1);
> $content1 = addslashes($content1);
> fclose($fp1);
> if(!get_magic_quotes_gpc())
> {
> $fileName1 = addslashes($fileName1);
> }
> }
> }
>
> ....
>
> if ($attch1) {
> $max_aid++;
> $attch_id1 = $max_aid; // attachment id
>
> $query = "INSERT INTO attachments VALUES ($attch_id1, '$fileName1',
> '$fileType1', '$fileSize1', '$content1')";
> $result = $connection->query($query);
> if (PEAR::isError($result)) {
> $query = "ROLLBACK";
> $result1 = $connection->query($query);
> die("Database query (ins attachment1) failed:
" .
> PEAR::errorMessage($result));
> }
> }
>
> ....
>

Re: file upload/download issue

am 11.09.2007 16:41:23 von Good Man

rafi wrote in news:1189514911.908560.133090
@r29g2000hsg.googlegroups.com:

> Hi,
>
> I developed a website using php5 & mysql5. One of its features is the
> ability of users to upload files to the server, and allow other users
> to
> view these files.
>
> I allow uploading the following file types: doc, pdf, txt, jpg, gif.
>
> My testing was done on two PCs:
> - PC1 with WinXP, IE7, OpenOffice
> - PC2 with WinXP, IE6, Office XP.
>
> I manage to successfully download and open files on PC1, but I have
> a problem on PC2 with IE6, where in the File Download dialog of IE, I
> cannot
> press Open and successfully open the file, but if I choose Save and
> then
> open the saved file, it works!

Sounds like PHP and everything is working fine, and that your issue is
really with IE6.

Re: file upload/download issue

am 14.09.2007 18:26:48 von Rafi

On Sep 11, 4:41 pm, Good Man wrote:
> rafi wrote in news:1189514911.908560.133090
> @r29g2000hsg.googlegroups.com:
>
>
>
>
>
> > Hi,
>
> > I developed a website using php5 & mysql5. One of its features is the
> > ability of users to upload files to the server, and allow other users
> > to
> > view these files.
>
> > I allow uploading the following file types: doc, pdf, txt, jpg, gif.
>
> > My testing was done on two PCs:
> > - PC1 with WinXP, IE7, OpenOffice
> > - PC2 with WinXP, IE6, Office XP.
>
> > I manage to successfully download and open files on PC1, but I have
> > a problem on PC2 with IE6, where in the File Download dialog of IE, I
> > cannot
> > press Open and successfully open the file, but if I choose Save and
> > then
> > open the saved file, it works!
>
> Sounds like PHP and everything is working fine, and that your issue is
> really with IE6. - Hide quoted text -
>
> - Show quoted text -

You are correct, it's an IE6 issue. To make sure that is the case, I
upgraded
IE6 to IE7 on PC2, and it worked perfectly.