Jump to content

[SOLVED] Opening local file


mfindlay

Recommended Posts

Hi,

I am relatively new to php and are trying to browse for a csv file on my computer and display it in a text area before doing some processing to sent to a database. I can open the file by using a simple script from my php book!:

 

<?php

echo ("<form>");

echo '<textarea cols="70" rows="15">';

$file= "file.csv";                                 

//open file

if ($file)

{

$data = fopen("$file", "r");

//read file

$line = 1;

$contents = fgets($data, 4096);

while (!feof($data))

{

echo ("$line: $contents");

$contents = fgets($data, 4096);

$line++;

}

fclose($data);

}

echo '</textarea><br />';

echo ("<input type=\"submit\" value=\"OK\" />");

echo '</form>';

?>

 

and I can browse for a file by...

<?php

echo ("<form enctype=\"multipart/form-data\" method=\"post\" action=\"upload.php\">");

echo ("<input type=\"hidden\" name=\"MAX_FILE_SIZE\" value=\"1000000\">");

echo ("<br />File to upload:<br />");

echo ("<input type=\"file\" name=\"file_name\" id=\"file_name\" size=\"30\">");

echo ("<p><input type=\"submit\" name=\"submit\" value=\"View\">");

echo ("</form>");

echo ("</div>");

?>

 

now when I change the $file="file.csv" to $file=$file_name or $file=$HTTP_GET_VARS['file_name'];

id doesnt display the file, I've also tried to put the 2 scripts in one file and use action=$PHP_SELF which results in a loop and the browser falling over...

any help would be much appreciated.

 

Cheers,

Mark.

 

Link to comment
https://forums.phpfreaks.com/topic/39094-solved-opening-local-file/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.