Jump to content

haku

Staff Alumni
  • Posts

    6,172
  • Joined

  • Last visited

  • Days Won

    2

Everything posted by haku

  1. innerHTML isn't a great practice anyways (maybe this is one of the reasons). You should be using appendChild for better practices.
  2. haku

    Drop Down

    I replied to this for you in the other forum.
  3. <p align=\"center\">[/code
  4. I would recommend not selecting * from the database, because that will also return the password. For security, you should never recover the password from the database. So choose the fields you want to recover and replace them with the star: "SELECT field1, field2 FROM draft WHERE password = '" . $password . "'";[/quote] Or else you can just get a count of the number of fields that have password in them: [code]"SELECT COUNT(*) FROM draft WHERE password = '" . $password . "'";[/quote] But you should actually be encrypting your passwords when they go in the database, so when you put them in, you should be using this code: [code]sha1($password) Meaning that when you check to see if they are in the database, it will look like this: "SELECT COUNT(*) FROM draft WHERE password = '" . sha1($password) . "'";[/quote] The last problem here is that if more than one user has this password, it will return a count of more than one. And if another user has this password, but the user you are checking doesn't, then it will still return a count of more than zero. So you should really have something like this: [code]"SELECT COUNT(*) FROM draft WHERE password = '" . sha1($password) . "' AND user='" . $username . "'"; [/code][/code][/code]
  5. Ya, this can't be done with PHP. If you get them to hit submit it can though, although it will require a call to the server, and the page will have to reload.
  6. I am forcing files on my server to be downloaded rather than opened in the browser using the following function: function output_file($file, $name, $mime_type='') { /* This function takes a path to a file to output ($file), the filename that the browser will see ($name) and the MIME type of the file ($mime_type, optional). If you want to do something on download abort/finish, register_shutdown_function('function_name'); */ if(!is_readable($file)) { die('File not found or inaccessible!'); } $size = filesize($file); $name = rawurldecode($name); /* Figure out the MIME type (if not specified) */ $known_mime_types=array( "pdf" => "application/pdf", "txt" => "text/plain", "html" => "text/html", "htm" => "text/html", "exe" => "application/octet-stream", "zip" => "application/zip", "doc" => "application/msword", "xls" => "application/vnd.ms-excel", "ppt" => "application/vnd.ms-powerpoint", "gif" => "image/gif", "png" => "image/png", "jpeg"=> "image/jpg", "jpg" => "image/jpg", "php" => "text/plain", "ppt" => "application/vnd.ms-powerpoint" ); if($mime_type=='') { $file_extension = strtolower(substr(strrchr($file,"."),1)); if(array_key_exists($file_extension, $known_mime_types)) { $mime_type=$known_mime_types[$file_extension]; } else { $mime_type="application/force-download"; } } @ob_end_clean(); //turn off output buffering to decrease cpu usage // required for IE, otherwise Content-Disposition may be ignored if(ini_get('zlib.output_compression')) { ini_set('zlib.output_compression', 'Off'); } header('Content-Type: ' . $mime_type); header('Content-Disposition: attachment; filename="'.$name.'"'); header("Content-Transfer-Encoding: binary"); header('Accept-Ranges: bytes'); /* The three lines below basically make the download non-cacheable */ header("Cache-control: private"); header('Pragma: private'); header("Expires: Mon, 26 Jul 1997 05:00:00 GMT"); // multipart-download and download resuming support if(isset($_SERVER['HTTP_RANGE'])) { list($a, $range) = explode("=",$_SERVER['HTTP_RANGE'],2); list($range) = explode(",",$range,2); list($range, $range_end) = explode("-", $range); $range=intval($range); if(!$range_end) { $range_end=$size-1; } else { $range_end=intval($range_end); } $new_length = $range_end-$range+1; header("HTTP/1.1 206 Partial Content"); header("Content-Length: $new_length"); header("Content-Range: bytes $range-$range_end/$size"); } else { $new_length=$size; header("Content-Length: ".$size); } /* output the file itself */ $chunksize = 1*(1024*1024); //you may want to change this $bytes_send = 0; if ($file = fopen($file, 'r')) { if(isset($_SERVER['HTTP_RANGE'])) fseek($file, $range); while(!feof($file) && (!connection_aborted()) && ($bytes_send<$new_length)) { $buffer = fread($file, $chunksize); print($buffer); //echo($buffer); // is also possible flush(); $bytes_send += strlen($buffer); } fclose($file); } else { die('Error - can not open file.'); } die(); } My problem is that the name of the file (called with '$name' when calling the function) is in Japanese. No matter what I do, the name comes out as gibberish. i have tried setting the accept encoding using the following header: header('Accept-Charset: Shift_JIS') as well as this: header('Content-Type: ' . $mime_type '; charset=Shift_JIS'); and a combination of both. I have also tried ISO-2022-JP and EUC-JP (the other two types of Japanese encoding), but none of them seem to work. Does anybody know what the header I need to set is in order for the file name to come out in proper Japanese and not be garbled? Thank you for your time.
  7. Thank you sir. Although, I don't really get it Where do I put this script?
  8. I am building a site in which users in my company can upload files onto our server, and download them as well. However, as I am working in Japan, the file names are often in Japanese. I have found that this doesn't bode so well for the server we use, so I have worked around this by changing the file name to a digit when it is uploaded, then storing a reference in a mysql database that matches the filename to the original Japanese name. However, this has left me with the problem that when the user downloads the file onto their computer, rather than seeing japanesefilename.extension, they see digit.extension. I know its possible to change the filenames as files are uploaded onto the server (Im already doing it), but is it possible to change the filename as files are downloaded to the client? If so, can someone point me in the right direction on how to do that? Thank you very much.
  9. If you want to be able to cross servers (or rather domains), you are probably going to have to use $_GET variables.
  10. Your method is both fairly un-secure as well as space consuming on the hard drive on which you are doing it. Why don't you use a database?
  11. Add a $_GET variable onto the url that you email to the administrator, then add a check to see if that variable is set on the page that the administrator ends up at. If the variable is set, have the script react accordingly. For example - someone orders item number 1. The page the administrator needs to look at is goods.php. Send this link to the admin: http://www.yoursite.com/goods.php?item=1 Then in goods.php add this code: <?php if(isset($_GET['item'])) { $query = "SELECT something FROM sometable WHERE item_number='". $_GET['item'] . "'"; ///query the database appropriately here }
  12. I'll add to that: Basically, this should be the very start of index.php: <?php checkUser(); ?> Before even your doctype or anything.
  13. The problem isn't where the header is, as the header is just part of a function. The problem is that wherever you are calling that function, it is after output has already been sent to the browser. Look closely at the location where that function is called, and then look and see what has been outputted to the browser before it is called. edit: on reading back to your earlier post, the offending line is calling for a link to the style sheet. You have to call that function before that line (and any other line that is outputting to the browser before that). It is line 7 - what have you got on lines 1-6?
  14. You can do it with Ajax, but this isn't the right forum for that.
  15. I got a 400 error so I couldn't see your output. But you have to add "echo" to the start of that image statement.
  16. echo "a line of text" . EUC . "The next line of text" This will output the following: a line of text The next line of text EUC adds a line break. Maybe this will help.
  17. Add this to your <form> tag: enctype="multipart/form-data" But what you have to realize is that this wont populate your database, rather it will just upload the file onto your server. If you want to add the path name to your database you will have write a script for that as well.
  18. The answer has already been given. Change it to type="submit". Submit buttons are not very easily stylized, they are also not a php issue.
  19. It cant be done without javascript. PHP runs entirely on the server, whereas a slideshow etc runs on the client. The server can't know what is happening on the client without either the user either clicking a link or pushing a button in order to send data to the server, or javascript executing some event that sends data to the server. Although I wonder if you maybe posted in the wrong thread? You arent the OP of this thread.
  20. What exactly is it that you want to do? Its hard to tell you anything without that info.
  21. You can try this: <form> //include necessary elements in form tag <input type="button" name="execute_function" value="Click" /> </form> And then on whatever page you are executing the code on, include this: <?php if(isset($_POST['execute_function'])) { click(); } ?> However, depending on what you are trying to do, a javascript function may serve you better. What is it that you want to do?
  22. Actually php has the ability to handle non-latin characters, but its not easy, and involves enabling the double byte character library using your php.ini file, and then setting the settings a proper way. I have never done it with Chinese or Russian, but I currently program sites in Japanese and have had to do it for Japanese character encoding. Its not easy by any means, but it can be done.
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.