Page 1 of 1

chdir("dir"); in HTML?

Posted: Wed Jul 26, 2006 4:20 am
by SomeOne
Pimptastic | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]


i have a question....
i have a form like this..

Code: Select all

<select name="dirselect" onChange="izberi mapo!">
      <option value="">Izberi mapo!</option>
	  
	
   <?php
	   $path = "./$slike";
      if ($handle = opendir($path))
   {
       $curDir = substr($path, (strrpos(dirname($path."/."),"/")+1));
       print "Trenutna mapa: ".$curDir."<br>"; 

       while (false !== ($file = readdir($handle)))
       {
           if ($file != "." && $file != "..")
           {
               $fName = $file;
               $file = $path.'/'.$file;
               if(is_dir($file))

               {
                   print "<option value=$fName>$fName</option>";
               }
           }
       }
       //chdir("$curDir");
	   closedir($handle);
   } 
    ?>
how could i add PHP? to this to change working directory if i select it from the list?
SomeOne 8O


Pimptastic | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]

Posted: Wed Jul 26, 2006 4:51 am
by Chris Corbyn
You'll need AJAX to do this. chdir() won't be persistent neither, it only last for the duration of the script executio (or the duration of the AJAX request) so you'll need to track movements in the session too.

Posted: Wed Jul 26, 2006 4:53 am
by SomeOne
hmmm
can i not have some function to change directory and the in onChange= start this function? :?

Posted: Wed Jul 26, 2006 5:05 am
by Benjamin
I just want to make sure that you are aware of the difference between client side vs server side code.

PHP is a server side scripting language. This means it is executed on your web server before the web page is sent to the browser.

Javascript is a client side scripting language. This means it is executed in your web browser, not on the server.

Javascript cannot execute PHP code. You can write Javascript which will send requests to the web server and dynamically update the web page in the browser, but the PHP is still executed on your web server. This is called AJAX.

If you view the source code for that page when you are viewing it in your browser, you will notice that all your PHP code isn't even there 8O

Posted: Wed Jul 26, 2006 5:09 am
by SomeOne
@astions
thnx..... i know that...though im a beginner in programing...im learning....sorry for stupid question :oops:
So basicly...i cant do a pull down menu containing directoryes and then change directory without JavaScript 8O

Posted: Wed Jul 26, 2006 5:15 am
by Benjamin

Posted: Wed Jul 26, 2006 5:16 am
by SomeOne
Thank you 4 help! :)

Posted: Wed Jul 26, 2006 7:33 am
by SomeOne
hmmmm....
so the pull down menu can be made in PHP though...must contain JavaScript...
Can anyone show me an example??? :oops:
i have tryed Rasmus AJAX tuttorial..though..dont have an idea how to pull this together :oops:

Posted: Wed Jul 26, 2006 8:29 am
by bokehman
SomeOne wrote:So basicly...i cant do a pull down menu containing directoryes and then change directory without JavaScript
Of course you can... it just requires a page reload.

Posted: Wed Jul 26, 2006 9:48 am
by SomeOne
yeah...i'we been thinking...
so can i do in PHP using $_POST :D

Posted: Wed Jul 26, 2006 10:47 am
by bokehman
SomeOne wrote:yeah...i'we been thinking...
so can i do in PHP using $_POST :D
Yes but if you are not going to use Javascript you would need a submit button in your form element.

Posted: Wed Jul 26, 2006 11:58 am
by daedalus__
If I was you, I would learn the AJAX way, talk about useful.

Posted: Wed Jul 26, 2006 12:06 pm
by bokehman
Daedalus- wrote:If I was you
Dont try to run before you can walk though. First learn PHP, then learn Javascript. Once you know them both to an advanced level then think about AJAX.

Posted: Wed Jul 26, 2006 12:47 pm
by feyd
ajax is way overkill for this. bokehman is suggesting the better route.

Posted: Wed Jul 26, 2006 12:55 pm
by daedalus__
^^