Hi folks,

I wanted to get the value of the clicked A href links, somebody please help.... i have something like this,

<a href="javascript: void(0)" onClick=window.open('<?php echo $rows['file_name']?>','welcome') style="border:0 ">View</a>

So i want to get the value if user clicks the href button. so please anybody...

Recommended Answers

All 12 Replies

I am not quite sure which value it is you want to get, but i will assume it is the filename. In that case, i would have done this:

<a href="#" target="_blank"
onClick="window.location='target.php?file=<?php echo $rows['file_name']?>'">View</a>

In this case, target.php is the file that is to process your value(filename).

Hope it helps.

Thank you for your response,
Actually this file_name is pdf file path so when this link clicks i want to open that pdf at the same time i want to take the time the user clicks the file and to save to database.. do u know how we can take this..???


I am not quite sure which value it is you want to get, but i will assume it is the filename. In that case, i would have done this:

<a href="#" target="_blank"
onClick="window.location='target.php?file=<?php echo $rows['file_name']?>'">View</a>

In this case, target.php is the file that is to process your value(filename).

Hope it helps.

You can try this. The page redirects to itself (pdf.php) when the link is clicked. The file then saves the time & user's session id before offering the file for download.

<?php
	session_start();

	if(isset($_GET['file']) && isset($_GET['click']) && $_GET['click']){
		//get user session
		$sessionID = session_id();

		//save time to db
		//$sql = "INSERT INTO visitors(session_id, time_clicked) VALUES('$sessionID', '".strftime("%X",time())."')" ;
		//mysql_query($sql);

		//prompt saving of the pdf
		$file = $_GET['file'] ;
		header("Content-type:application/pdf");		
		header("Content-Disposition:attachment;filename='$file'");
	}

	$file = "cert.pdf";
	echo "<a href='pdf.php?click=true&file=$file'>Download File</a>";

?>

Thank You wilch its worked thanks a lot....


You can try this. The page redirects to itself (pdf.php) when the link is clicked. The file then saves the time & user's session id before offering the file for download.

<?php
	session_start();

	if(isset($_GET['file']) && isset($_GET['click']) && $_GET['click']){
		//get user session
		$sessionID = session_id();

		//save time to db
		//$sql = "INSERT INTO visitors(session_id, time_clicked) VALUES('$sessionID', '".strftime("%X",time())."')" ;
		//mysql_query($sql);

		//prompt saving of the pdf
		$file = $_GET['file'] ;
		header("Content-type:application/pdf");		
		header("Content-Disposition:attachment;filename='$file'");
	}

	$file = "cert.pdf";
	echo "<a href='pdf.php?click=true&file=$file'>Download File</a>";

?>

You're welcome :)

HI wilch Like if the pdf file is there in another directory what will do its downloading but the correct path its not saving.. suppose i have saved the project in project folder and pdf is der in project/upload folder then what will do for the download code its downloading but the correct path its not getting..

You're welcome :)

I am not sure i am getting your problem clearly. But, if you mean the file is not downloading because the file is in a different folder location. Then alter the code to this:

<?php
	session_start();

	if(isset($_GET['file']) && isset($_GET['click']) && $_GET['click']){
		//get user session
		$sessionID = session_id();

		//save time to db
		//$sql = "INSERT INTO visitors(session_id, time_clicked) VALUES('$sessionID', '".strftime("%X",time())."')" ;
		//mysql_query($sql);

		//prompt saving of the pdf
		$file = $_GET['file'] ;
		//header("Content-type:application/pdf");		
		//header("Content-Disposition:attachment;filename='$file'");
		header("location:$file");
	}

	$file = "../cert.pdf"; //or $file = "projects/file/cert.pdf";
	echo "<a href='pdf.php?click=true&file=$file'>Download File</a>";

?>

The same thing only i want but just i want open the pdf in the next window.. would u know..??? sorry if i am troubling u....

I am not sure i am getting your problem clearly. But, if you mean the file is not downloading because the file is in a different folder location. Then alter the code to this:

<?php
	session_start();

	if(isset($_GET['file']) && isset($_GET['click']) && $_GET['click']){
		//get user session
		$sessionID = session_id();

		//save time to db
		//$sql = "INSERT INTO visitors(session_id, time_clicked) VALUES('$sessionID', '".strftime("%X",time())."')" ;
		//mysql_query($sql);

		//prompt saving of the pdf
		$file = $_GET['file'] ;
		//header("Content-type:application/pdf");		
		//header("Content-Disposition:attachment;filename='$file'");
		header("location:$file");
	}

	$file = "../cert.pdf"; //or $file = "projects/file/cert.pdf";
	echo "<a href='pdf.php?click=true&file=$file'>Download File</a>";

?>

I am not sure how to open it up in a new window. But, i think the same code should open the pdf in a new window if the user's browser has a PDF viewer plugin installed on it, so my guess is that if you dont a PDF plugin on your browser, then the browser defaults to the download option.
Like i said, this is a guess - i am not too sure about it.

okay then how i can take the particular clicked file name to store in data table

I am not sure how to open it up in a new window. But, i think the same code should open the pdf in a new window if the user's browser has a PDF viewer plugin installed on it, so my guess is that if you dont a PDF plugin on your browser, then the browser defaults to the download option.
Like i said, this is a guess - i am not too sure about it.

within the if clause, change the old sql statement to the following:

$sql = "INSERT INTO visitors(session_id, time_clicked, file_name) VALUES('$sessionID', '".strftime("%X",time())."', '$file')" ;

Obviously, i am assuming you have a field called file_name in your table.

Okay wilch thanks for your support its been solved as per my requirement.. thank you... have a good day....

with regards
Jithesh

within the if clause, change the old sql statement to the following:

$sql = "INSERT INTO visitors(session_id, time_clicked, file_name) VALUES('$sessionID', '".strftime("%X",time())."', '$file')" ;

Obviously, i am assuming you have a field called file_name in your table.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.