How to use <a> tag and pass one parametar?
Posted: Fri Aug 27, 2010 3:33 am
I have one page where i list directories and files in xampp directory. But now i want to put all files in <a> tag so i could click on them and to open them for editing. But i don't know how to pass parametar in a tag. Here is the code:
So when i click on one file it opens file:
For now i just want to pass parametar i show it on the screen.
When i click on one of files i get in the address bar of browser
so parametar is blank. Also screen is blank.
Obviously problem is:
P.S. I am beginer in php programming.
Code: Select all
<?php
$DOCUMENT_ROOT=$_SERVER['DOCUMENT_ROOT'];
function get_dirs($dir){
global $dirs;
if (!isset($dirs)){$dirs = '';}
if(substr($dir,-1) !== '\\'){$dir .= '\\';}
if ($handle = opendir($dir)){
$dirs .="<ul>";
while (false !== ($file = readdir($handle))){
if ($file != "." && $file != ".."){
if(filetype($dir.$file) === 'dir')
{
clearstatcache();
$dirs .= "<li>" . $file . "</li>";
get_dirs($dir . $file);
}
else
{
//$dirs .= "<li>" . $file . "</li>";
$dirs .= "<li><a href=\"otvaranje_fajla.php?naziv=\"" . $file . "\">" . $file . "</a></li>";
}
}
}
$dirs .="</ul>";
closedir($handle);
}
return $dirs;
}
//C:\\xampp\\htdocs
$direktorijumi=get_dirs("$DOCUMENT_ROOT");
echo "$direktorijumi";
?>
So when i click on one file it opens file:
Code: Select all
<?php
$nazivFajla=$_GET['naziv'];
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>
<?php
echo "Naziv fajla je $nazivFajla";
?>
<body>
</body>
</html>For now i just want to pass parametar i show it on the screen.
When i click on one of files i get in the address bar of browser
Code: Select all
http://localhost/otvaranje_fajla.php?naziv=Obviously problem is:
Code: Select all
$dirs .= "<li><a href=\"otvaranje_fajla.php?naziv=\"" . $file . "\">" . $file . "</a></li>";P.S. I am beginer in php programming.