chdir("dir"); in HTML?

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
SomeOne
Forum Commoner
Posts: 27
Joined: Tue Jul 25, 2006 2:06 am

chdir("dir"); in HTML?

Post 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]
User avatar
Chris Corbyn
Breakbeat Nuttzer
Posts: 13098
Joined: Wed Mar 24, 2004 7:57 am
Location: Melbourne, Australia

Post 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.
User avatar
SomeOne
Forum Commoner
Posts: 27
Joined: Tue Jul 25, 2006 2:06 am

Post by SomeOne »

hmmm
can i not have some function to change directory and the in onChange= start this function? :?
User avatar
Benjamin
Site Administrator
Posts: 6935
Joined: Sun May 19, 2002 10:24 pm

Post 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
User avatar
SomeOne
Forum Commoner
Posts: 27
Joined: Tue Jul 25, 2006 2:06 am

Post 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
User avatar
Benjamin
Site Administrator
Posts: 6935
Joined: Sun May 19, 2002 10:24 pm

Post by Benjamin »

Last edited by Benjamin on Wed Jul 26, 2006 5:16 am, edited 1 time in total.
User avatar
SomeOne
Forum Commoner
Posts: 27
Joined: Tue Jul 25, 2006 2:06 am

Post by SomeOne »

Thank you 4 help! :)
User avatar
SomeOne
Forum Commoner
Posts: 27
Joined: Tue Jul 25, 2006 2:06 am

Post 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:
User avatar
bokehman
Forum Regular
Posts: 509
Joined: Wed May 11, 2005 2:33 am
Location: Alicante (Spain)

Post 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.
User avatar
SomeOne
Forum Commoner
Posts: 27
Joined: Tue Jul 25, 2006 2:06 am

Post by SomeOne »

yeah...i'we been thinking...
so can i do in PHP using $_POST :D
User avatar
bokehman
Forum Regular
Posts: 509
Joined: Wed May 11, 2005 2:33 am
Location: Alicante (Spain)

Post 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.
User avatar
daedalus__
DevNet Resident
Posts: 1925
Joined: Thu Feb 09, 2006 4:52 pm

Post by daedalus__ »

If I was you, I would learn the AJAX way, talk about useful.
User avatar
bokehman
Forum Regular
Posts: 509
Joined: Wed May 11, 2005 2:33 am
Location: Alicante (Spain)

Post 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.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

ajax is way overkill for this. bokehman is suggesting the better route.
User avatar
daedalus__
DevNet Resident
Posts: 1925
Joined: Thu Feb 09, 2006 4:52 pm

Post by daedalus__ »

^^
Post Reply