[PHP] Passing JAVASCRIPT variable to PHP Script...
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. See my progress: upload.php # Checking for the File existance if (file_exists($fullPath)) { echo script language='JavaScript'if(confirm('This file is already Exists ! Do You Want to Duplicate ?')) { var s=1;} else {var s=0;} /script; $decide=script language='JavaScript'document.write(s)/script; echo $decide; if (!$decide) { // Don't Upload exit; } else { // Upload the file } In this code, echo $decide; is printing whether 1 or 0. But by using that variable, i cudn't proceed further. Bcoz it is not useful for manipulating. * Is anyway to store that variable value in a static file, so that, i can proceed easily. * Is it possible to execute shell commands by javascript, so that i can create file store this variable. If it is not possible, plz give any other solution. Expecting ur reply. Thanks in advance Prabhakaran. -- View this message in context: http://www.nabble.com/Passing-JAVASCRIPT-variable-to-PHP-Script...-tf2415628.html#a6733549 Sent from the PHP - General mailing list archive at Nabble.com. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Passing JAVASCRIPT variable to PHP Script...
On Tue, 10 Oct 2006 03:09:42 -0700 (PDT), Captain [EMAIL PROTECTED] 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. See my progress: upload.php # Checking for the File existance if (file_exists($fullPath)) { echo script language='JavaScript'if(confirm('This file is already Exists ! Do You Want to Duplicate ?')) { var s=1;} else {var s=0;} /script; $decide=script language='JavaScript'document.write(s)/script; echo $decide; if (!$decide) { // Don't Upload exit; } else { // Upload the file } In this code, echo $decide; is printing whether 1 or 0. But by using that variable, i cudn't proceed further. Bcoz it is not useful for manipulating. * Is anyway to store that variable value in a static file, so that, i can proceed easily. * Is it possible to execute shell commands by javascript, so that i can create file store this variable. If it is not possible, plz give any other solution. Expecting ur reply. Thanks in advance Prabhakaran. -- View this message in context: http://www.nabble.com/Passing-JAVASCRIPT-variable-to-PHP-Script...-tf2415628.html#a6733549 Sent from the PHP - General mailing list archive at Nabble.com. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php This is my ideas: If the file has already existed, the server-side script could save it in a place temporarily, and marks the file by an unique identification (such as md5 checksum). And then the the server-side tells the client-side file exists and gives it the id. If the user choose overwrite, the client-side only need to post the received id, do not need to upload the file again. -- Sorry for my poor English. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Passing JAVASCRIPT variable to PHP Script...
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
Re: [PHP] Passing JAVASCRIPT variable to PHP Script...
At 3:09 AM -0700 10/10/06, Captain wrote: If it is not possible, plz give any other solution. Expecting ur reply. It's possible, but why not do it in php -- it's simpler -- like: ?php // specify the directory where the uploaded file should end up $path = 'upload/' ; // specify the filetypes allowed $allowed = array('image/gif','image/pjpeg','image/jpeg','image/png'); // specify the max filesize in bytes $max_size = 20; if(isset($HTTP_POST_FILES['userfile'])) { if(is_uploaded_file($HTTP_POST_FILES['userfile']['tmp_name'])) { if($HTTP_POST_FILES['userfile']['size'] $max_size) { if(in_array($HTTP_POST_FILES['userfile']['type'],$allowed)) { if(!file_exists($path . $HTTP_POST_FILES['userfile']['name'])) { if(@rename($HTTP_POST_FILES['userfile']['tmp_name'],$path.$HTTP_POST_FILES['userfile']['name'])) { $html_output = 'Upload sucessful!br'; $html_output .= 'File Name: '.$HTTP_POST_FILES['userfile']['name'].'br'; $html_output .= 'File Size: '.$HTTP_POST_FILES['userfile']['size'].' bytesbr'; $html_output .= 'File Type: '.$HTTP_POST_FILES['userfile']['type'].'br'; $image = $HTTP_POST_FILES['userfile']['name'] ; }else{ $html_output = 'Upload failed!br'; if(!is_writeable($path)) { $html_output = 'The Directory '.$path.' must be writeable!br'; }else{ $html_output = 'an unknown error ocurred.br'; } } }else{ $html_output = 'The file already existsbr'; } }else{ $html_output = 'Wrong file typebr'; } }else{ $html_output = 'The file is too bigbr'; } } }else{ $html_output = 'form method=post enctype=multipart/form-data action='.$_SERVER['PHP_SELF'].''; $html_output .= 'input type=file name=userfile'; $html_output .= 'input type=submit value=upload'; $html_output .= '/form'; } echo 'htmlheadtitleUploader/title/headbody'; echo $html_output; echo '/body/html'; ? Expecting ur payment. tedd -- --- http://sperling.com http://ancientstones.com http://earthstones.com -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Passing JAVASCRIPT variable to PHP Script...
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