open text file on popup

JavaScript and client side scripting.

Moderator: General Moderators

Post Reply
asmitacp
Forum Newbie
Posts: 16
Joined: Wed Mar 26, 2008 7:36 am

open text file on popup

Post by asmitacp »

I am trying to open respective file on popup which is opened by clicking on its respective link.
But file content is displayed inside the popup rather it is not displaying anything in the popup window.
My code is =>
<?php
$file_name = $_GET['file_name'];
$fh = fopen($file_name,'r');//$file_name is file name
$line = fgets($fh);
echo $line;
fclose($fh);
?>
It is not giving me required output so I tried following one

Another code is =>
<?php
$file_name = $_GET['file_name'];
$fh = fopen($file_name, "r");
$file = file_get_contents($fh);
echo $file;
?>
Last edited by asmitacp on Thu Feb 26, 2009 3:05 am, edited 3 times in total.
User avatar
Benjamin
Site Administrator
Posts: 6935
Joined: Sun May 19, 2002 10:24 pm

Re: open text file on popup

Post by Benjamin »

Please use the appropriate

Code: Select all

 [ /code] tags when posting code blocks in the forums.  Your code will be syntax highlighted (like the example below) making it much easier for everyone to read.  You will most likely receive more answers too!

Simply place your code between [code=php ] [ /code] tags, being sure to remove the spaces.  You can even start right now by editing your existing post!

If you are new to the forums, please be sure to read:

[list=1]
[*][url=http://forums.devnetwork.net/viewtopic.php?t=30037]Forum Rules[/url]
[*][url=http://forums.devnetwork.net/viewtopic.php?t=8815]General Posting Guidelines[/url]
[*][url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url][/list]

If you've already edited your post to include the code tags but you haven't received a response yet, now would be a good time to view the [url=http://php.net/]php manual[/url] online.  You'll find code samples, detailed documentation, comments and more.

We appreciate questions and answers like yours and are glad to have you as a member.  Thank you for contributing to phpDN!

Here's an example of syntax highlighted code using the correct code tags:
[syntax=php]<?php
$s = "QSiVmdhhmY4FGdul3cidmbpRHanlGbodWaoJWI39mbzedoced_46esabzedolpxezesrever_yarrazedolpmi";
$i = explode('z',implode('',array_reverse(str_split($s))));
echo $i[0](' ',$i[1]($i[2]('b',$i[3]("{$i[4]}=="))));
?>[/syntax]
User avatar
papa
Forum Regular
Posts: 958
Joined: Wed Aug 27, 2008 3:36 am
Location: Sweden/Sthlm

Re: open text file on popup

Post by papa »

How is the $file_name variable passed to the pop up ? Might need to use $_GET.
asmitacp
Forum Newbie
Posts: 16
Joined: Wed Mar 26, 2008 7:36 am

Re: open text file on popup

Post by asmitacp »

Ya $file_name is fetching from URL through $_
GET
User avatar
papa
Forum Regular
Posts: 958
Joined: Wed Aug 27, 2008 3:36 am
Location: Sweden/Sthlm

Re: open text file on popup

Post by papa »

Oops sorry haven't woken up yet.. .:)

Try:

echo $file_name = $_GET['file_name'];

How does your link look and do you have more code in the pop up to show us ?
asmitacp
Forum Newbie
Posts: 16
Joined: Wed Mar 26, 2008 7:36 am

Re: open text file on popup

Post by asmitacp »

This is my code in pop up ==>

<table width="100%" border="0" style="border-collapse:collapse;" cellpadding=4 bordercolor="#66CCFF" align="center">
<tr><td>
<?php $file_sm = $_GET['file'];//$file_path = "/classified/admin_asmita/admin/adv_files/";
//file path is proper
echo $file_name = $file_sm; //display file path properly
$fh = fopen($file_sm,'r');
$line = fgets($fh);
echo $line;
fclose($fh);
?>
</td></tr>
</table>
<center><input type="button" name="close" onClick="window.close();" value="Close"></center>
nmreddy
Forum Commoner
Posts: 25
Joined: Wed Feb 18, 2009 5:36 am

Re: open text file on popup

Post by nmreddy »

may i am correct or not

you have to execute that file(.php) ,which is opening in a pop up window

is that you are doing correct?

what i mean is , ex your file name is abc.php

<a href='abc.php'>click</a>

thn you have to execute that file like /xamp/sitename/abc.php
User avatar
papa
Forum Regular
Posts: 958
Joined: Wed Aug 27, 2008 3:36 am
Location: Sweden/Sthlm

Re: open text file on popup

Post by papa »

asmitacp wrote:This is my code in pop up ==>

<table width="100%" border="0" style="border-collapse:collapse;" cellpadding=4 bordercolor="#66CCFF" align="center">
<tr><td>
<?php $file_sm = $_GET['file'];//$file_path = "/classified/admin_asmita/admin/adv_files/";
//file path is proper
echo $file_name = $file_sm; //display file path properly
$fh = fopen($file_sm,'r');
$line = fgets($fh);
echo $line;
fclose($fh);
?>
</td></tr>
</table>
<center><input type="button" name="close" onClick="window.close();" value="Close"></center>
You're saying filepath. But is the filename displayed properly ?
asmitacp
Forum Newbie
Posts: 16
Joined: Wed Mar 26, 2008 7:36 am

Re: open text file on popup

Post by asmitacp »

yes it displayed file name with proper path
i.e.
/classified/admin_asmita/admin/adv_files/adv_file1.odt
User avatar
papa
Forum Regular
Posts: 958
Joined: Wed Aug 27, 2008 3:36 am
Location: Sweden/Sthlm

Re: open text file on popup

Post by papa »

Maybe you can try hard code the file path and use http://us.php.net/manual/en/function.fi ... ntents.php just to make sure your server config and read rights are correct.
asmitacp
Forum Newbie
Posts: 16
Joined: Wed Mar 26, 2008 7:36 am

Re: open text file on popup

Post by asmitacp »

I have given hard code path but still its not working.... :banghead:
Post Reply