mfindlay Posted February 19, 2007 Share Posted February 19, 2007 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 More sharing options...
printf Posted February 19, 2007 Share Posted February 19, 2007 Your form is posting a file, so your uploaded file will be found in the SUPER GLOBAL $_FILE['file_name']. Link to comment https://forums.phpfreaks.com/topic/39094-solved-opening-local-file/#findComment-188273 Share on other sites More sharing options...
mfindlay Posted February 19, 2007 Author Share Posted February 19, 2007 Thanks, I was thinking about this the wrong way and trying to view file from my local machine....have to upload to server >veiw from there > process and send data to database > delete uploaded file from server. Cheers, Mark. Link to comment https://forums.phpfreaks.com/topic/39094-solved-opening-local-file/#findComment-188499 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.