Forum Moderators: coopster

Message Too Old, No Replies

generate csv fields into index.html

client doesn't want php extension

         

silver_wing

9:54 am on Jul 27, 2004 (gmt 0)

10+ Year Member



Hi, i've got a problem.

It was started when my client want create a online shopping, so i make it using php. the reguirement for this web is the web first must download the datafeed in csv (coma separated value) format. after download, the web generate all field in csv format into file named index.html.

The problem is : how to generated all the csv field into index.html?

i'm try to make index.php, but the customer doesnt want in php format. can anybody help me?

for your knowledge, here i copy my 3 file :
1. Download_datafeed.php
<snip> Relevant code:
<form name="form1" method="post" action="wget.php" enctype="">
<p>Insert your merchant address :
<input name="link" type="text" id="link">
<input type="submit" name="Submit" value="Download"></p>
</form>
<snip>

2. file wget.php (for download the datafeed)
<p>#!/usr/bin/php -q
<?php

echo "\tDownload - [$link\n";...]

//do download now
$url = "http://" . $link;
$file = fopen("$url", "rb");

if (!$file) {
echo "$url - gagal\n";
continue;
}

$fname = basename("http://$link");
$curpath = $_SERVER["PWD"];

mkdir("csv");
$namafile = "csv/$fname";
$thefile= fopen($namafile,"wb");
$local="localhost/azwar/index.php";
$namalocal=fopen($local,"wb");

while (!feof($file)) {
$line = fgets ($file, 1024);
fputs($thefile, $line);
}
fclose ($thefile);

$contents=fread($namalocal,filesize($local));
fclose($local);
echo $contents;
/*$filename = "index.html";
if(!($myFile = fopen($filename, "wb")))
{
print("Error: ");
print("'$filename' could not be created\n");
exit;
}

//write some lines to the file
fputs($myFile, "Save this line for later\n");
fputs($myFile, "Save this line too\n");

//close the file
fclose($myFile);

if(!($myFile = fopen($filename, "r")))
{
print("Error:");
print("'$filename' could not be read\n");
exit;
}

while(!feof($myFile))
{
//read a line from the file
$myLine = fgets($myFile, 1024);
print("$myLine <BR>\n");
}

//close the file
fclose($myFile);
*/

//chmod($namafile, 0777);

//if downloaded

echo filesize($namafile);

?>
</p>
<p><strong>Click <a href="index.php">Here</a> to continue.</strong></p>
<p>&nbsp; </p>

3. File index.php (it should be index.html, but i cant make it)

<snip>irrelevant code</snip>

Does anybody help me? Plsss. its very urgent for me.

Thanx a lot....

[edited by: coopster at 4:19 pm (utc) on July 27, 2004]
[edit reason] Trimmed code dump; please see Posting Guidelines as mentioned [/edit]

RonPK

10:12 am on Jul 27, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Hello there silver wing,

You may want to have a look at the Posting Guidelines in this forum's charter...

Also, "but the customer doesnt want in php format": well, no scripting & no database queries for that customer, then.

Good luck!

ergophobe

7:38 pm on Jul 27, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Actually, by "php format" he seems to mean files named *.php

This is easy, just do a rewrite using .htaccess and mod_rewrite.
Something like this

RewriteEngine on
RewriteRule ^(.*)\.html?(.*)$ $1.php.$2 [L]

should take any url like

h**p://domain/dir/page.html?action=buy

and change it into

h**p://domain/dir/page.php?action=buy

Alternatively, if you want, you can just set up your server so that *.html and *.htm files as php. That's an even better solution if you don't mind having all your *.html files parsed as php and have sufficient privileges on the server (if you can do mod_rewrite, you should be able to this too).

Tom

RonPK

9:59 pm on Jul 27, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Ah, now I see.

Yeah, lots of sites I know parse .htm with PHP and serve .html unparsed.

silver_wing

2:06 am on Jul 28, 2004 (gmt 0)

10+ Year Member



Ooopss, sory for the source code. i dont read the guidelines first.

Ok.

sorry, but the answer that u gave to me is not the right asnwer. Maybe this time, my explanation will explain to you.

ok, the customer came to me and he want me to make a website for him. the requirements is the web MUST download the datafeed (in CSV form), and generate all field in csv into html file.

Based on the needs, so, i successfuly made a file named download_datafeed.php for download the datafeed. But, after that, i confused. How to display all the field that we download in download_datafeed.php into file html (just say the file named index.html)?

As long as i know, html file cannot receive coding in php format right? so, how to display the field?

Can anybody help me how to make it?

i read the answer that you gave to me that says we must rewrite the engine. Well, truly, the customer doesnt allow me to configure the engine....

He wants, that file ALWAYS in html file...

once again, i realy need your help...

David_O

2:21 am on Jul 28, 2004 (gmt 0)

10+ Year Member



Try editing you .htaccess file, to parse .htm/.html files as php. Here's how I did it:

AddType application/x-httpd-php .htm
AddType application/x-httpd-php .html

Good Luck!