Page 1 of 1
Caling a Function from a php generated <A HREF>
Posted: Fri Feb 18, 2005 10:14 am
by moiseszaragoza
Calling a Function from a php generated <A HREF>
I have been trying to attach a function to a php generated <a href> but I cant figured it out.
Posted: Fri Feb 18, 2005 10:15 am
by Maugrim_The_Reaper
You might say what you're trying to accomplish, and what you've been trying thus far...
here is my code
Posted: Fri Feb 18, 2005 10:16 am
by moiseszaragoza
Code: Select all
<?php
$dir = "../../../myDirectory/";
// Open a known directory, and proceed to read its contents
if (is_dir($dir)) {
if ($dh = opendir($dir)) {
while (($file = readdir($dh)) !== false) {
echo "<a href='#'>Delete File </a> <a href='$dir$file' target='_self'>filename: $file : </a>" . "<br>";
}
closedir($dh);
}
}
feyd | 
Posted: Fri Feb 18, 2005 10:22 am
by feyd
you cannot directly attach any php functions to a html link, they are on seperate sides of requests: php is server-side (at this time), and html is client-side.
The code you posted isn't trying to attach a function or any php code to a link. If anything, it'd just attempt to give a link to a file/directory in $dir.
So my real problem is
Posted: Fri Feb 18, 2005 10:22 am
by moiseszaragoza
Code: Select all
<?php
$dir = "../../../myDir/";
// Open a known directory, and proceed to read its contents
if (is_dir($dir)) {
if ($dh = opendir($dir)) {
while (($file = readdir($dh)) !== false) {
echo "<a href='WHAT GOES HERE TO CALL MY FUNCTION'>Delete File </a> <a href='$dir$file' target='_self'>filename: $file : </a>" . "<br>";
}
closedir($dh);
}
}
Code: Select all
<?php
function DeletemyFile($dir,$file)
{
unlink($dir$file)
echo "the file : $file has been deleted from: $dir ";
}
?>
Posted: Fri Feb 18, 2005 10:25 am
by feyd
you need a script for delete processing, that accepts some form of data on which file(s) to delete.
How would I pass data from point A to point B
Posted: Fri Feb 18, 2005 10:27 am
by moiseszaragoza
How would I pass data from point A to point B
Posted: Fri Feb 18, 2005 10:32 am
by feyd
pass some form of identification via the url:
http://www.yoursite.com/deletescript.php?file=foo.gif
$_GET['file'] = 'foo.gif';
this is basic scripting 101 stuff..
Posted: Fri Feb 18, 2005 10:33 am
by moiseszaragoza
Let me try to explain what I want to do.
I have a php script displays the files I have on a directory to the browser. I want to be able to choose witch file I want to delete.
But I need to be able to choose witch file I want to delete
Posted: Fri Feb 18, 2005 10:36 am
by feyd
and my last post is pointing you in the direction to head for that..

Posted: Fri Feb 18, 2005 10:48 am
by moiseszaragoza
My Script on de Show Files
Code: Select all
<?php
$dir = "../../../mydir/";
// Open a known directory, and proceed to read its contents
if (is_dir($dir)) {
if ($dh = opendir($dir)) {
while (($file = readdir($dh)) !== false) {
echo "<a href='Deletefile.php?file=$file'>Delete File </a> <a href='$dir$file' target='_self'>filename: $file : </a>" . "<br>";
}
closedir($dh);
}
}
?>
So my script on the delete page should look like :
Code: Select all
<?php
$file = $_GETї'file']
function DeletemyFile($file)
{
//unlink($dir$file)
echo "the file : $file has been delete ";
}
?>
But wen I run it I get an error
Parse error: parse error, unexpected T_FUNCTION in Directory/Deletefile.php on line 4
and line 4 has
1 <?php
2 $file = $_GET['file']
3
4 function DeletemyFile($file)
5 {
6 //unlink($dir$file)
7 echo "the file : $file has been delete ";
8 }
9 ?>
Posted: Fri Feb 18, 2005 3:46 pm
by feyd
you forgot a semicolon on the $from setting line. Your delete file does not call the function defined in it.
Posted: Fri Feb 18, 2005 5:48 pm
by John Cartwright
Also $dir will not be read within the function. You must pass the variable through the function call like you did with $file
ie. DeletemyFile($file,$dir)