roadhog481 Posted January 30, 2007 Share Posted January 30, 2007 Hi, I’m working on my company's intranet and creating a "live directory". All that means is that all of the departments have a separate directory that they can throw files into and I create a virtual directory off the "intranet" web server (IIS 5/PHP 4.4.2) to that folder/index.php.All the script does is read the directories and creates list items for them then it reads the files, excludes a few and creates another set of list items, the style sheet comes in after that. It is a work in progress and is growing as I learn how to do more things. The problem is that my users are too dumb to copy an index.php file to the new sub directory they've just created, so I was looking for a way I could have a function that upon clicking the link to get to the newly created folder it actually goes ahead and verifies that that file is in there. If it is not in there then copy it from a master folder.Is this even possible? And if it is could someone give me a direction to go in because I’m absolutely stumped.[code]echo '<div id=path>';echo str_replace('/', ' ', dirname($_SERVER['PHP_SELF'])); echo '</div></div>';echo '<div id=navcontainer><ul id=tabnav>';$handle = opendir("./");while (($file = readdir($handle))!==false) { if(is_dir($file)){ if($file != "." && $file != ".."){ echo "<li><a href=$file>$file</a></li>"; } }}if ( isset($execute) ){ checkindexexists();}echo "</ul><div class=content><ul>"; $handle = opendir("./");while (($file = readdir($handle))!==false) { if(is_file($file)){ if($file != "." && $file != ".."){ $split = explode(".", $file); $proper = $split[0]; $ext = $split[1]; if ($ext !== 'php'){ if ($proper !== stristr($proper, '~')){ $filename = rawurlencode($file); echo "<li><a href=$filename>$proper</a></li>\n"; } } } }}echo "</ul></div>";closedir($handle);[/code] Quote Link to comment https://forums.phpfreaks.com/topic/36404-function-help/ Share on other sites More sharing options...
Quoth Posted January 31, 2007 Share Posted January 31, 2007 hmmm, I am very new to php, so sorry if I go off on the wrong track or suggest to use things the wrong way. I am sure someone will correct me if I am wrong :Dapparently if you try to open a file to read and append, "if the file does not exist, php attempts to create it" (using: fopen("filename.php, "a+"); )you dont have to do anything with it if it does exist, but if it doesn't you could write what you need and close the file.just a thought, I've been trying to learn about files, and that was my first thought.Cheers! Quote Link to comment https://forums.phpfreaks.com/topic/36404-function-help/#findComment-173228 Share on other sites More sharing options...
roadhog481 Posted January 31, 2007 Author Share Posted January 31, 2007 Thanks, but how do i get it to open the folder and do this before it goes into it. I have already tried to do something like this onclick event but i can seem to get it to work.[code] <?phpfunction myfunction(){echo("<strong>I love PHP !</strong><br>");}?><a href="<?php echo("$PHP_SELF?execute=myfunction")?>">click to execute myfunction ! </a><p><?php if ( isset($execute) ){myfunction();}?>[/code]thanks Quote Link to comment https://forums.phpfreaks.com/topic/36404-function-help/#findComment-173615 Share on other sites More sharing options...
roadhog481 Posted February 1, 2007 Author Share Posted February 1, 2007 in the function above, does it execute before the folderchange? Quote Link to comment https://forums.phpfreaks.com/topic/36404-function-help/#findComment-175024 Share on other sites More sharing options...
Daniel0 Posted February 1, 2007 Share Posted February 1, 2007 Updating your code: [code]<?phpfunction myfunction(){ echo "<strong>I love PHP !</strong>";}?><a href="<?php echo "{$_SERVER['PHP_SELF']}?execute=myfunction"; ?>">click to execute myfunction!</a><?phpif(isset($_GET['execute'])){ myfunction();}?>[/code]Changes: echo is a language construct, not a function, therefore it does not need () around them. Changed to not use register_globals - it's not safe. $PHP_SELF doesn't always work, replaced it with $_SERVER['PHP_SELF'].[quote author=roadhog481 link=topic=124781.msg519383#msg519383 date=1170368573]in the function above, does it execute before the folderchange?[/quote]PHP is run server-side, so you cannot execute a PHP function without calling the script again. You might want to check out AJAX. Quote Link to comment https://forums.phpfreaks.com/topic/36404-function-help/#findComment-175037 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.