Re: Passing JAVASCRIPT variable to PHP Script...

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Captain wrote:
> Hi geeks,
>           i am uploading a file to server. Uploading part is working fine. i
> am struggle with minor part. actually before uploading file, i am checking
> for existance of a file. If it is not exists, directly i am uploading that
> file. If it exists, i sud ask user that "This file is exits. Do You really
> want to Upload it?"...If YES, i will overwrite it. otherwise, i won't do
> anything.
>          i am using javascript for popup windows. i used confirm()
> function(CANCEL / OK).
>          the problem is, i am not able to get the variable value for php
> script. Of course, php is server side programming language & javascript
> client side programming language.
> Plz see my code & give the solution.

You hit the nail right on the head, javascript is client side, PHP is
server side.  This means that PHP completely finishes it's execution
before the javascript starts to run.


To get this to work you need to do most of the work in the javascript.

Prompt the user for the file and the filename.
In javascript send a request to the PHP server and pass the filename as
a GET or POST variable.
The PHP script that recieves this checks if the file exists and echos
true of false for the javascript to recieve, the PHP script then exists.
The javascript recieves this value and prompts the user to confirm if
the file exists.
The javascript can then handle the false value or make an upload request
if the file is to be sent.

This kind of processing is generally refered to as AJAX, searching on
that term will give you a whole pile of examples.


David

PS: Geeks isn't normally seen as a complimentary term.

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux