Jump to content

Recommended Posts

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]



Link to comment
https://forums.phpfreaks.com/topic/36404-function-help/
Share on other sites

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 :D

apparently 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!
Link to comment
https://forums.phpfreaks.com/topic/36404-function-help/#findComment-173228
Share on other sites

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] <?php
function 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
Link to comment
https://forums.phpfreaks.com/topic/36404-function-help/#findComment-173615
Share on other sites

Updating your code: [code]<?php
function myfunction()
{
echo "<strong>I love PHP !</strong>";
}
?>

<a href="<?php echo "{$_SERVER['PHP_SELF']}?execute=myfunction"; ?>">click to execute myfunction!</a>

<?php
if(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.
Link to comment
https://forums.phpfreaks.com/topic/36404-function-help/#findComment-175037
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.