Log in

View Full Version : OT:Is this the right forum for HTML help?


Ruatha
August 13th, 2003, 10:16 AM
I need the ability on my site to let the user download a file by pressing a button.
That is no problem, but the file is a zip file that changes name each turn, i e NGC3_57.zip, NGC3_58.zip" etc.
I don't want to change the HTML code each turn, I just want to put the file in the right directory and remove the old one, then when you press the icon to download, it will choose the only file in that directory.
I can't see anyway to get wildcards in a HTML link, and I haven't found any good CGI script for it (Don't script myself).
Any ideas?

And I'd also like a way to make a list of all files in a directory on a HTML page with other contents, not a simple link to the directory. This list must also be dynamicly changed when the contents change. It's to let you see through the web page who has uploaded their turns, but not to download the files.

Suggestions??

(I only use Perl CGI, no java or ASP or other fancy stuff)

[ August 13, 2003, 10:12: Message edited by: Ruatha ]

narf poit chez BOOM
August 13th, 2003, 10:46 AM
far as i can tell, this is sort of a general forum, as long as it doesn't get to general.

i wonder if that'll make sense tommorrow.

Fyron
August 13th, 2003, 11:13 AM
I could write you a PHP script in maybe 5 minutes if you want to use that (tomorrow though, as it is time for slumber now). http://forum.shrapnelgames.com/images/icons/icon12.gif Don't know any PERL/CGI though.

Ruatha
August 13th, 2003, 11:23 AM
What would be needed for my server to run a PHP script? (Will look it up now)

Thanks for the offer.

Ruatha
August 13th, 2003, 02:10 PM
It's the easy way out, but then it's harder for the one's downloading as it then wants to owerwrite the previous zipped turn.
They would also have to download it and unpack it to verify that it is indeed the latest turn and that I haven't messed up.
With the turn number in the file name it's easier for both them and me to know that all is ok.

I'd prefer to keep it to PBW standards.

[ August 13, 2003, 13:12: Message edited by: Ruatha ]

tesco samoa
August 13th, 2003, 02:27 PM
here is the article that explains it in php

http://www.devshed.com/Server_Side/PHP/File_Manipulation/page1.html

http://newdev.com/ws/?downloading has a perl script called down ad which is a downloader

http://www.sitepoint.com/article/1156

article on how to write a perl script on downloadin files

perhaps the best way to do it is to set up a script to read the directory of contents ( only put that file in there) then pass this info over to your download part... as you now know the name. That way you do not have to rename the file every time

or do what sj said so you can download that file.

tesco samoa
August 13th, 2003, 02:28 PM
i guess if you read the directory of contents... then you can just let them download what ever...

Ruatha
August 13th, 2003, 03:03 PM
I have been pointing to the directory so far but I don't think that's a "nice" solution.
Will check the links.

The "down ad" wants a fixed filename I belive...
Will check how to do it myself then,

thanx

[ August 13, 2003, 14:09: Message edited by: Ruatha ]

Ruatha
August 13th, 2003, 03:16 PM
Darned again.
The do it yourself works for me, but you have a fixed filename....

http://ruatha.homelinux.org/test.htm

[ August 13, 2003, 14:32: Message edited by: Ruatha ]

rdouglass
August 13th, 2003, 03:29 PM
It's too bad you can't use ASP. I have a script that lists contents of any folder / file. You can sort, hide certain extensions, etc. I use it VERY frequently in our Intranet for issues just such as yours....

tesco samoa
August 13th, 2003, 03:31 PM
here is how you do that in php
this file will read everything in the directory and the person can right click and save as
just put this as a file in the directory and then call it download.php or something and get the person to link to that. you can add stuff to it etc... to make it all pretty like

1060781471.zip (http://forum.shrapnelgames.com/newuploads/1060781471.zip)

tesco samoa
August 13th, 2003, 03:32 PM
installing php is easy... php.net

Ruatha
August 13th, 2003, 03:35 PM
I don't want them to be able to download from the list.
The CGI upload form works great.
the do it yourself download form works with fixed file names.

What I want is a table with the files in the turnfiles directory, and a way to get an automatic download of the only file in the gamefile directory when you press the download current gameturn icon

This is how it looks now:

http://ruatha.homelinux.org

[ August 13, 2003, 14:37: Message edited by: Ruatha ]

Ruatha
August 13th, 2003, 03:47 PM
Just a way to get all filenames in a directory into a variable would be very helpful.

geoschmo
August 13th, 2003, 04:41 PM
Well, the simplest solution would be for you to just name the current .zip file without the turn number. If the latest file is always the same name the download link never changes. You just overwrite it when you upload it for the players to get.

Geoschmo

Ruatha
August 13th, 2003, 05:11 PM
Originally posted by Ruatha:
It's the easy way out, but then it's harder for the one's downloading as it then wants to owerwrite the previous zipped turn.
They would also have to download it and unpack it to verify that it is indeed the latest turn and that I haven't messed up.
With the turn number in the file name it's easier for both them and me to know that all is ok.

I'd prefer to keep it to PBW standards.<font size="2" face="Verdana, Helvetica, sans-serif">

tesco samoa
August 13th, 2003, 05:20 PM
sorry ruthia i do not know perl at all

Ruatha
August 13th, 2003, 05:27 PM
Originally posted by tesco samoa:
sorry ruthia i do not know perl at all<font size="2" face="Verdana, Helvetica, sans-serif">I almost doesn't know it either, it's just an acquaintance, not a friend.

gravey101
August 13th, 2003, 05:28 PM
Just a way to get all filenames in a directory into a variable would be very helpful.

In perl, just use opendir and readir thus;

$directory = '/tmp/files';
@files = ();
opendir (DIR, $directory);
while ($file = readdir(DIR)) {
push @files, $file;
}
closedir(DIR);

and @files has your list of files.

[ August 13, 2003, 16:30: Message edited by: gravey101 ]

Ruatha
August 13th, 2003, 05:54 PM
Thanx, will test this!

Ruatha
August 13th, 2003, 06:48 PM
It fixed one of the problems, the one with listing the files, now I just need to fix the upload.

THANX!!!

Hey, maybe, I can use the same solution for that one... will see

[ August 13, 2003, 17:50: Message edited by: Ruatha ]

Ruatha
August 13th, 2003, 08:03 PM
I've made a script with your help that finds the right filename but when it shall download it it says "no such file", arghh!

Fyron
August 13th, 2003, 08:28 PM
Make sure to chmod the permissions of the uploads folder to 777, or else people will not be able to upload files there (need public write access and all).

Ruatha
August 13th, 2003, 08:49 PM
Uploading has been working all the time.
The current turn file download kind of works now, but it only downloads a short part (100Bytes or so) of the file, and it just want's to give it the extension .CGI

I store the Zip file in a single array @fileholder or string $fileholder.
Those are propably to small variables to hold the entire file.
Need to find a better way.

more work!

[ August 13, 2003, 20:02: Message edited by: Ruatha ]

tesco samoa
August 13th, 2003, 09:23 PM
644 will work for read access

Perhaps you should just write a telnet script to get the file

777 is good for upload...

Suicide Junkie
August 14th, 2003, 01:56 AM
Why not just rename the file to "NGC3_Latest.zip" ?

Ruatha
August 14th, 2003, 03:53 AM
Access is not a problem, direct linking the files works great.
It's just my inadequacy at writing scripts that's the problem.

Current status:
Newbie Galactic Combat 3 emergency Site (http://ruatha.homelinux.org)

tesco samoa
August 14th, 2003, 04:12 AM
nice ruthia sorry i could not help.

so how did it all go ??????

Ruatha
August 14th, 2003, 04:19 AM
I'll install PHP and write me a script in that as it seems easier, good learning possibility http://forum.shrapnelgames.com/images/icons/icon7.gif

Fyron
August 14th, 2003, 04:35 AM
Well if you want to write it yourself, guess that leaves me off the hook. http://forum.shrapnelgames.com/images/icons/icon12.gif But if you do want me to, just tell me specifically what you want the script to do.

Ruatha
August 14th, 2003, 05:25 AM
Originally posted by Imperator Fyron:
Well if you want to write it yourself, guess that leaves me off the hook. http://forum.shrapnelgames.com/images/icons/icon12.gif But if you do want me to, just tell me specifically what you want the script to do.<font size="2" face="Verdana, Helvetica, sans-serif">Ok, I'll let you do the job and then see if I can understand how it works, here goes:

When pressing the link
<a href="gamefile"><img border=0 width=34 height=34
src="images/getturn.png">Get latest game turn file <br></a>
it should find the first file in the directory gamefile and initiate a download to the client of that file.

the href="gamefile" ofcourse can be substituted for whatever, it's the icon and text in the link that needs to be preserved.

gamefile is a subdirectory to the server directory which is d:\data\server

Doable?
PHP is installed now and seems to work ok.

[ August 14, 2003, 04:27: Message edited by: Ruatha ]

Fyron
August 14th, 2003, 05:28 AM
What do you mean by "first file in the directory"? You can sort files in any order you want, so there isn't a first file. Do you mean the file containing the latest turn? That should be fairly easy, just a simple while loop testing each file to see if it has a larger number than the Last.

Also, how are the files named? Do you name them all the same way, but just with a different number in each filename?

[ August 14, 2003, 04:29: Message edited by: Imperator Fyron ]

Ruatha
August 14th, 2003, 05:36 AM
Hey.
PHP looks much easier than CGI, why didn't I check this out before?

Fyron
August 14th, 2003, 05:44 AM
Dunno. Care to answer my question? http://forum.shrapnelgames.com/images/icons/icon12.gif

Fyron
August 14th, 2003, 05:51 AM
I have your script written, I just need to know what the file naming scheme is. http://forum.shrapnelgames.com/images/icons/icon12.gif

Actually, go here to see it in action:

http://www.spaceempires.net/ruatha/

There are 4 files in the folder:
ng1.zip
ng01.zip
ng12.zip
ng3.zip

You can d/l the script here:

http://www.spaceempires.net/ruatha/index.zip

You will need to set the appropriate path info and such, as commented in the script.

[ August 14, 2003, 04:53: Message edited by: Imperator Fyron ]

Ruatha
August 14th, 2003, 05:55 AM
Sure.
When I do a script that looks for files in the directory it dirst returns the directorys "." and ".." and then a filenamen for the turn file, and I don't want it to try and download the current or above directory !
The turnfiles are named NGC3_57.zip with 57 variable.

I've done this but it seems to download into the browser and view the file there, and it gives header errors and I can't seem to get the path right!
So I'll be watching your script when it comes!!

That is propably what you'll get when you try to patch several scripts together!

[ August 14, 2003, 05:00: Message edited by: Ruatha ]

Ruatha
August 14th, 2003, 05:56 AM
Originally posted by Imperator Fyron:
I have your script written, I just need to know what the file naming scheme is. http://forum.shrapnelgames.com/images/icons/icon12.gif

Actually, go here to see it in action:

http://www.spaceempires.net/ruatha/

There are 4 files in the folder:
ng1.zip
ng01.zip
ng12.zip
ng3.zip

You can d/l the script here:

http://www.spaceempires.net/ruatha/index.zip

You will need to set the appropriate path info and such, as commented in the script.<font size="2" face="Verdana, Helvetica, sans-serif">Thanx, will check it out now!

Ruatha
August 14th, 2003, 06:04 AM
Good,
I changed the path and the Last character from g to _ and so far it works ok.

Thanx Fyrons PHP script at my site (Not incorporated yet) (http://ruatha.homelinux.org/index.php)

Now I just need it to start an automatic download instead of making a link....

This is the script I made prior to yours, it finds the right file but as I said I get header errors and it shows the content in the browser:
http://ruatha.homelinux.org/test.txt


Warning: Cannot modify header information - headers already sent by (output started at d:\data\server\test.php:1) in d:\data\server\test.php on line 38

Warning: Cannot modify header information - headers already sent by (output started at d:\data\server\test.php:1) in d:\data\server\test.php on line 40

Warning: Cannot modify header information - headers already sent by (output started at d:\data\server\test.php:1) in d:\data\server\test.php on line 42

Warning: Cannot modify header information - headers already sent by (output started at d:\data\server\test.php:1) in d:\data\server\test.php on line 50

Warning: Cannot modify header information - headers already sent by (output started at d:\data\server\test.php:1) in d:\data\server\test.php on line 52

Warning: Cannot modify header information - headers already sent by (output started at d:\data\server\test.php:1) in d:\data\server\test.php on line 54

Warning: Cannot modify header information - headers already sent by (output started at d:\data\server\test.php:1) in d:\data\server\test.php on line 58

Warning: Cannot modify header information - headers already sent by (output started at d:\data\server\test.php:1) in d:\data\server\test.php on line 60

Warning: Cannot modify header information - headers already sent by (output started at d:\data\server\test.php:1) in d:\data\server\test.php on line 62

and then it starts to show text of the content of the zip file, not what I had in mind!

[ August 14, 2003, 05:22: Message edited by: Ruatha ]

Fyron
August 14th, 2003, 06:34 AM
Well... I am not really a PHP expert, so I am not sure about those header lines. If the syntax is correct, it may be that your install of PHP does not support them or something. My guess would be that they are not really necessary though...

Don't forget to format the page how you want. http://forum.shrapnelgames.com/images/icons/icon12.gif The easiest way would be to include a HTML file before and after the echo statements, such as this:

include ("header.html");

These files would just be the portions of the page above and below where the turn file is to be displayed.

Ruatha
August 14th, 2003, 06:39 AM
It seems to have something with not being allowed to send any information to the browser before the headers, I've removed all text output before the headers but still...

If the headers aren't needed, how to make the browser download the file without the need of clicking any link??

[ August 14, 2003, 05:41: Message edited by: Ruatha ]

Ruatha
August 14th, 2003, 06:43 AM
There was one space character infront of <?php
that messed all up, now I'm getting somewhere http://forum.shrapnelgames.com/images/icons/icon7.gif

The only remaining problem is taht it wants to add the extension .php to the file, so the suggested filename in the download dialogue is NGC3_57.zip.php

Hmm, how to remove that??

I had to change the Content-Type header to x-zip-compressed and now it works great.

[ August 14, 2003, 05:57: Message edited by: Ruatha ]

Fyron
August 14th, 2003, 06:51 AM
If the headers aren't needed, how to make the browser download the file without the need of clicking any link??
<font size="2" face="Verdana, Helvetica, sans-serif">Oh, I didn't realize that is what you wanted it to do. I have no idea how to do that.

Fyron
August 14th, 2003, 06:54 AM
This looks like you are cutting off the file extension, and I see no line to add a new one:

$fname = basename($file);

So that might cause problems. http://forum.shrapnelgames.com/images/icons/icon12.gif

Ruatha
August 14th, 2003, 07:01 AM
Nope, now all is working, it was the content type.
Thanx for the help, I chose your way to find the file instead of mine as if I use yours I can just copy new files into the directory and leave the old ones, but with mine I had to delete the old ones.
So:
http://ruatha.homelinux.org

press "Get latest game turn file" for the script, and here is the script finished:

http://ruatha.homelinux.org/upload.txt

I removed the line
$fname = basename($file);
as it had not use, just a reminder of something previously tested.

[ August 14, 2003, 06:57: Message edited by: Ruatha ]

Fyron
August 14th, 2003, 07:03 AM
Cool. http://forum.shrapnelgames.com/images/icons/icon7.gif Glad I could help.

Ruatha
August 14th, 2003, 10:58 AM
Ahh, this PHP is fun, now I've made it more PBW like with players upload status on the first page.

Thanx for starting me on PHP!

[ August 14, 2003, 10:07: Message edited by: Ruatha ]

Ruatha
August 14th, 2003, 11:53 AM
Another question, I added a timer counting down to the deadline, does the TIME() get's the time from my server or from the clients computer?

Now I've changed all old CGI scripts to PHP scripts, much better!

[ August 14, 2003, 12:40: Message edited by: Ruatha ]

tesco samoa
August 14th, 2003, 05:36 PM
http://us2.php.net/manual/en/ref.datetime.php

has all the differnt time functions.

Ruatha
August 14th, 2003, 07:05 PM
Thanks, but I don't find the answer myself to my question there. I guess it's the servertime.

Ruatha
August 15th, 2003, 09:28 PM
Now that I see how much easier PHP is than CGI that I used to use I start wondering about ASP, is that good?
there seems to be some things that can't be done in PHP that can be done in ASP.

Perhaps I'll check that and transform the site to ASP instead of PHP (instead of Perl/CGI), or what about Java/Javabeans and VB scripts, are those only clientbased?

I think I'll start by looking into ASP some.

BTW the site files can be found here:
http://www.shrapnelgames.com/cgi-bin/ultimatebb.cgi?ubb=get_topic;f=23;t=009759

Fyron
August 15th, 2003, 10:25 PM
What can you do in ASP that you can't do in PHP?

Ruatha
August 15th, 2003, 10:29 PM
A upload pogress bar, the only ways to do it in PHP are seriously complicated.
Involving java scripts and applying a user made patch to the PHP program.....

Sleep time, se ya.

tesco samoa
August 16th, 2003, 06:19 PM
rutha it is good to know both. ( if you really wish to learn both you will build it in asp and then in php or the other way around )

Ruatha
August 16th, 2003, 06:27 PM
Yes, I'll try to convert it to ASP in the future, and add some functions aswell.