Closed Thread Icon

Topic awaiting preservation: File download not working? (Page 1 of 1) Pages that link to <a href="https://ozoneasylum.com/backlink?for=12536" title="Pages that link to Topic awaiting preservation: File download not working? (Page 1 of 1)" rel="nofollow" >Topic awaiting preservation: File download not working? <span class="small">(Page 1 of 1)</span>\

 
Gee
Bipolar (III) Inmate

From: London, UK
Insane since: Nov 2002

posted posted 12-01-2002 23:15

Hi again scientists,

Ok, I created a couple of scripts to upload files, store them in a directory and store the file information in mysql, then I created a script for people to view the file details and download them through html links.

Everything works fine apart from no matter what I try, the damn files will not download, they just open up either in the browser if they are a text file or open in thier respective player if they are a multimedia file. I have been playing around with this all weekend without success

Can you spot my problem? Can you help me - please?

code:
<html>
<head>
<title> grabFiles.php </title>
</head>

<body bgcolor="#FFE3BB" >

<?

// Grabdetails.php:
//Takes all the details of the
//new file posted from the form
//and adds them to the lecfiles
//table of projectg DB.


foreach ($_POST as $k => $v){
echo "<li> $k - $v \n";
}
?><br> <br>

<?

//This section gets the file as well as
//the automatic file details
//and copies it to the destination dir


if ($_FILES['yourFile'] != "") {

copy($_FILES['yourFile']['tmp_name'], "C:\\FoxServ\\www\\lectures\\".$_FILES['yourFile']['name'])
or die("Couldn't copy the file!");
}

else {
die("No input file specified");
}

$filePath = "C:\\FoxServ\\www\\lectures\\".$_FILES['yourFile']['name'];


//Make sure both a full description and
//file have been entered
if (!$_POST['modCode'] &#0124; &#0124; !$_POST['modTitle'] &#0124; &#0124; !$_POST['lecturer'] &#0124; &#0124; !$_POST['week'] &#0124; &#0124; !$_POST['topics'])
{
echo "You have not completed the form correctly,
Please go back and try again.";
exit;
}

$modCode = addslashes($modCode);
$modTitle = addslashes($modTitle);
$lecturer = addslashes($lecturer);
$week = addslashes($week);
$topics = addslashes($topics);
$filePath = addslashes($filePath);

$db = mysql_connect("localhost", "gee", "ftm");

if (!$db)
{
echo "Error: Gee could not connect to database";
exit;
}

mysql_select_db("projectg");
$query = "insert into lecfiles VALUES
(0, '{$_POST['modCode']}', '{$_POST['modTitle']}', '{$_POST['lecturer']}', '{$_POST['week']}', '{$_POST['topics']}', '{$filePath}')";
$result = mysql_query($query);

if ($result)
echo "Data inserted into Database.";


echo "<br><br><a href='getdetails.php'>Add Another File</a>"; ?>

<p>

<h1>Success!</h1>

<P>You sent: <? echo $_FILES['yourFile']['name'] ?>, a <? echo $_FILES['yourFile']['size'];
?> byte file with a mime type of <? echo $_FILES['yourFile']['type']; ?>.</p>


Destination: <? $filePath = stripSlashes($filePath); echo $filePath ?>
<br><br><br>
<a href="showdetails.php">View Updated List</a>


</body>
</html>


code:
<?
//showdetails.php
//this script displays a list of all the files stored in the db
//and contains a link to each file so they can be downloded


//DB connection variables
$db = mysql_connect("localhost", "gee", "ftm");

if (!$db)
{
echo "Error: could not connect to database - Please try again later";
exit;
}

mysql_select_db("projectg");
$query = "SELECT modCode, modTitle, lecturer, week, topics, filePath ";
$query .= "FROM lecfiles ";
$query .= "ORDER BY modCode, Week ASC";

$result = mysql_query($query);

if (!$result) {
echo "...............Couldn't get file list";
}

?>

<!-- edit this below -->

<img border=0 src="mdxlogo.gif"></a>

<table border="1" cellpadding="0" cellspacing="0" bordercolor="#111111" width="100%">

<tr>

<td width="15%" bgcolor="#FF9900" height="21">
<p style="margin-left: 10"><b><font size="2" face="Verdana" color="#FFFFFF">
Module Code</font></b></td>

<td width="15%" bgcolor="#FF9900" height="21">
<p style="margin-left: 10"><b><font face="Verdana" size="2" color="#FFFFFF">
Mudule Title</font></b></td>

<td width="15%" bgcolor="#FF9900" height="21">
<p style="margin-left: 10"><b><font face="Verdana" size="2" color="#FFFFFF">
Lecturer</font></b></td>

<td width="15%" bgcolor="#FF9900" height="21">
<p style="margin-left: 10"><b><font face="Verdana" size="2" color="#FFFFFF">
Week</font></b></td>

<td width="15%" bgcolor="#FF9900" height="21">
<p style="margin-left: 10"><b><font face="Verdana" size="2" color="#FFFFFF">
Topics</font></b></td>

<td width="15%" bgcolor="#FF9900" height="21">
<p style="margin-left: 10"><b><font face="Verdana" size="2" color="#FFFFFF">
filePath</font></b></td>

</tr>

<?

while($row = mysql_fetch_array($result))
{

?>

<tr>
<td width="15%" bgcolor="#FFDCA8" height="21">
<p style="margin-left: 10; margin-right: 10">
<font face="Verdana" size="1">
<?php echo "{$row['modCode']}"; ?>
</font>
</td>

<td width="15%" bgcolor="#FFDCA8" height="21">
<p style="margin-left: 10">
<font face="Verdana" size="1">
<?php echo "{$row['modTitle']}"; ?>
</font>
</td>

<td width="15%" bgcolor="#FFDCA8" height="21">
<p style="margin-left: 10">
<font face="Verdana" size="1">
<?php echo "{$row['lecturer']}"; ?>
</font>
</td>

<td width="15%" bgcolor="#FFDCA8" height="21">
<p style="margin-left: 10">
<font face="Verdana" size="1">
<?php echo "{$row['week']}"; ?>
</font>
</td>

<td width="15%" bgcolor="#FFDCA8" height="21">
<p style="margin-left: 10">
<font face="Verdana" size="1">
<?php echo "{$row['topics']}"; ?>
</font>
</td>

<td width="15%" bgcolor="#FFDCA8" height="21">
<p style="margin-left: 10">
<font face="Verdana" size="1">
<!--got to investigate this -->

<a href="<?php echo "{$row['filePath']}"; ?>">Download now </a> <!--works sort of -->
</font>
</td>


<?
}

echo "</table>";

?>



Gee
Bipolar (III) Inmate

From: London, UK
Insane since: Nov 2002

posted posted 12-01-2002 23:20

PS. I can post the formas well if that helps?
Gee

Rooster
Bipolar (III) Inmate

From: the uterus
Insane since: Nov 2002

posted posted 12-02-2002 00:53

If you?re talking about the same thing I?m thinking of, I don?t thing there is a real easy way to fix the problem. It doesn?t have anything to do with your PHP script it?s more of a HTML/Browser problem. Different browsers will do different things with the file extensions used in URL?s. For instance, if you were to click on link to a MS Word Document while using IE, the document would be opened inside the browser window. This happens because an OLE interface has been associated with the file extension. However if you were to do the same in Netscape, the browser will ask the client what they want to do with the document. If the client chooses to open the file on the spot it will be opened using a separate instance of MS Word, this is because NS can?t handle the OLE interface object and leaves the file handling up to the program that has been associated with the file extension.

I?ve actually been trying to do the same thing, except force the file to be opened instead of downloaded. I haven?t really found any way to specify how the extension should be handled using HTML and I?m not sure if there is a way; but I hope I?m soooo wrong.

If this isn?t what you?re talking about it might help to post a link to an example page so we could see the problem in action, and also view the parsed HTML.


..
~Existence is a mere pattern.~

Gee
Bipolar (III) Inmate

From: London, UK
Insane since: Nov 2002

posted posted 12-02-2002 01:49

http://172.186.41.179/getdetails.php

Rooster
Bipolar (III) Inmate

From: the uterus
Insane since: Nov 2002

posted posted 12-02-2002 02:32

O, your having a problem ~uploading~ a file, you said, ?the damn files will not download?. Sorry about that, I thought you were talking after they had already beed uploaded.

Yes, you need to put information about the maximum file size to be uploaded inside the form. It?s a hidden input element that looks like this...

<input type=?hidden? name=?MAX_FILE_SIZE? value=?1000?>

The value is the maximum file size in bytes. It should work after that?


..
~Existence is a mere pattern.~

[This message has been edited by Rooster (edited 12-02-2002).]

Gee
Bipolar (III) Inmate

From: London, UK
Insane since: Nov 2002

posted posted 12-02-2002 02:40

nope, I can upload fine - no problems with that.
you can upload a file too but you must follow the guidelines below

All fields in the form must be submitted
Module code = anything up to 7 characters
Module title = anything up to 50 characters
Lecturer = anything up to 50 characters
week = must be a digit as it is of tinyint type
topics = anything up to 255 characters

I know uploads definately work as I have already tested it from a remote machine over the net.

Rooster
Bipolar (III) Inmate

From: the uterus
Insane since: Nov 2002

posted posted 12-02-2002 02:58

Well I uploaded a file and made my way to this page...
http://172.186.41.179/showdetails.php

Where it asked me if I wanted to download one of the files available, but I can?t really verify anything for you because you have all the links going to Fox Server on your C drive.

i.e. C:\FoxServ\www\lectures\Sunset.jpg

Thus all I got was DNS errors.


[edit]As for the files opening in there associated programs, I suggest just putting a note on the page somewhere that says, ?Right click, save target as to download?. [/edit]

..
~Existence is a mere pattern.~

[This message has been edited by Rooster (edited 12-02-2002).]

Gee
Bipolar (III) Inmate

From: London, UK
Insane since: Nov 2002

posted posted 12-02-2002 03:40

Yep - that is the problem.
All the files that are uploaded are stored in C:\FoxServ\www\lectures\
So if I change the filePath to...
$filePath = "http://172.186.41.179/C:\Foxserv\www\lectures".$_FILES['yourFile']['name'];
And point the link to filePath that should be correct!

Well, this is getting better cause now at least the link is pointing to the correct place...
now I get this problem...

You don't have permission to access /C:/Foxserv/www/lectures/~$oup Project.doc on this server.
Additionally, a 404 Not Found error was encountered while trying to use an ErrorDocument to handle the request.

hmmmm - thats gotta have something to do with apache me thinks?
What I cannot understand is apache allows file uploads to that directory
but doesn't allow downloads.

[This message has been edited by Gee (edited 12-02-2002).]

Rooster
Bipolar (III) Inmate

From: the uterus
Insane since: Nov 2002

posted posted 12-02-2002 04:03

Are you trying to make a web server out of the Fox Server you have. If so, I think Fox Server is only configured to be used for local testing of PHP and MySQL... i.e. http://localhost/somefile.php

If you want to make a real web server out of it, you have to reconfigure the Apache, MySQL and PHP because all are set so you can not access them from an outside host. But I?ve never used Fox Server so I'm not positive.


..
~Existence is a mere pattern.~

Gee
Bipolar (III) Inmate

From: London, UK
Insane since: Nov 2002

posted posted 12-02-2002 04:23

No - foxserver is just the name of the directory. Foxserv is just an application that automatically installs apache, php, mysql in 1 go - then the user must configure everything
to get their own preferences. Thats what I am doing at the moment - reading through the apache documentation to find out how to allow users to get permission to download from my specified directory.

PS. I appreciate your help - keep your thoughts coming!

Rooster
Bipolar (III) Inmate

From: the uterus
Insane since: Nov 2002

posted posted 12-02-2002 05:04

I realize what foxserv is, I use a similar product called, phpdev. It?s just that I think both are mainly distributed for the purpose of testing PHP and MySQL on a localhost; thus why they come configured as such.

The problem is, in order for PHP to be secure; you need to reconfigure the settings and then recompile the affected modules. Unless FoxServ does this for you, then your server environment will not be secure. If it does recompile PHP then I might just change the package I?ve been using.

If you?re just going to use it as storage and not run any PHP on it, it might not be a problem. But don?t quote me on that.

As for the Apache, I know it needs to be reconfigured but think all the needed settings are in the *.conf files.


..
~Existence is a mere pattern.~

Gee
Bipolar (III) Inmate

From: London, UK
Insane since: Nov 2002

posted posted 12-02-2002 06:50

Fixed it - nearly...
one of the problems was that the links were absolute to the server, not for clients,...in that I mean,.. clients cannot access http://172.186.41.179/C:/Foxserv/www/lectures/
but they can access http://172.186.41.179/lectures/

So I changed the link and now clients can download by right-clicking the link and using 'save as'.
If a user does a left-click though - the file will open automatically.
I wonder if there is a way of forcing the download to use the save as / open / cancel menu box as default?

PS. I have had to take the pages down temporarily - but I will put them back up later on today!

[This message has been edited by Gee (edited 12-02-2002).]

DmS
Paranoid (IV) Inmate

From: Sthlm, Sweden
Insane since: Oct 2000

posted posted 12-02-2002 09:48

Hi there, oh boy, do I remember that problem...
We built a large document-archive for office files om an intranet and got this exact problem.
Never did find a reliable solution though

The base of the problem is exactly what Rooster wrote, but that's not enough when it comes to IE...
(as if anything is...)

What you can try is to set up the server/script to pass a faked header to the browser, example:
If extension is .txt, .doc, .xls and so on, send a ".zip header" to the browser, that MIGHT fool the browser that it's recieving something that it can't open, that way it will display the open?/save? box.
That is however depending on what the user has answered earlier in that box, you know, the little checkbox "always do like this when you get this type of file"... That part you have absolutley no control over.

Unfortunatley this solution isn't as reliable as it should be.
Usually a browser sends a request for a file, get's the file header, decides what to do and then displays it accordingly to the program/user settings.

IE however is a bit different since it's so tightly integrated with the OS. What IE does is actually two calls for each request. Like this, request file, examine header AND the actual file to determine if they match, if they don't, the examination of the actual file wins, in effect negates the sent headers. Then another call is made and the file is displayed accordingly to the result of the examination.

As you see, it's not that easy to decide for the browser what to do with what formats.
However, if anyone else has a solution, I'm also very interested in an example.
/Dan

{cell 260}
-{ a vibration is a movement that doesn't know which way to go }-

« BackwardsOnwards »

Show Forum Drop Down Menu