Re: Passing JAVASCRIPT variable to PHP Script...

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

 



On Tue, October 10, 2006 5:09 am, Captain wrote:
> Hi geeks,

Hi, non-listener...

You do realize you posted much the same question yesterday, right?

Do you think our answer will have changed in 24 hours?

Actually, it will change.

I have GIVEN UP trying to tell you the RIGHT WAY to do this, and will
blindly answer your question giving you BAD ADVICE.

The remainder of this email is BAD ADVICE and I do not recommend
anybody other than "Captain" follow it.

You have been warned.

>           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.

Here are 2 ways to do this:

1. In the PHP script that dumps out the INPUT NAME="upload"
TYPE="FILE" add something like this:

<script language="javascript">
  var file_exists = new Array;
<?php
  $i = 0;
  $upload_dir = "/full/path/to/dir/where/you/store/uploads/";
  $dir = opendir($upload_dir) or die("Failed to open $upload_dir");
  while (($file = readdir($dir)) !== false){ //this is subtle, do not
simplify
    echo "  file_exists[", $i++, "] = '$file';\n";
  }
?>
</script>

You can then check in javascript with something like:
if (file_exists[document.upload.value].length){
  alert('Overwrite?');
}


Another option is to use AJAX in your JS to check back to a URL on the
server that lists all the files already used.

Note that NEITHER of these guarantees that the file won't exist
because some OTHER user uploaded the same name file while yours was
being uploaded.

> 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.

You say "Of course" so blithely, but clearly do not yet understand the
implications of that statement.

-- 
Some people have a "gift" link here.
Know what I want?
I want you to buy a CD from some starving artist.
http://cdbaby.com/browse/from/lynch
Yeah, I get a buck. So?

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