Jump to content

programming.name

Members
  • Posts

    46
  • Joined

  • Last visited

Everything posted by programming.name

  1. Hi, there. Is that bad practice not to have tag Ids except when needed? What about name and class? Are they necessary, and what happen if they don't appear Thanks in advance
  2. Hi, I'm trying to make some kind of image preview. I am currently using native html5 tag output and fileReader object in javascript. It works great with me but my target browser doen't support it. So I decided to go with xmlhttprequest to get this job done. It also works perfectly. My ajax image preview basically does the following: if an user select an image file from local disk, the onselect event fires the javascript function preview(). What it does is first, the file is uploaded to the desired folder, and the image will be displayed with the img tag. And if another file is chosen then the file currently uploaded is removed(in terms of server space) and new chosen image is uploaded to the server. So far so good. But if a tricky user keeps previwing image like 50 times or so, is that still fine? I'm just concerned about server overhead. Is this considered to be "heavy"? File size limit is 3MiB. If is this acceptable approach for normal, good, "tame" users? I need your advice. Thanks.
  3. Hi, Is that possible to implement an effect that F11 key is pressed automatically on load? I mean I'm trying to maximize the window and I don't want to actually resize the window with the window object. I rather to use the keycode to get the same effect as if I press the F11 key manually to "REALLY" maximize the window. (with auto-hide-and-show address bar) I want to return the value of keycode on load and I found that most browsers'(at least my target browsers) value for F11 is 122. So I tried the following: test.html <body onload="return max_win(event)"> test.js function get_keycode(e) { if (window.event) { keycode=event.keyCode; } else { keycode= e.which; } } function max_win(e) { get_keycode(e); return keycode=122; } It does nothing. can anyone fix my problem please? Thanks inadvance.
  4. Hi, Is there an acceptable way to call a method in a class from another class? I have 3 files and 2 classes as below: a.php class a { function func_a() { b::func_b //it is a place where I want to call func_b() and this give me an error } } b.php class b { function func_b() { echo 'I got in!'; } } c.php <?php include("a.php")// or require_once include("b.php")// or require_once $a = new a; $b = new b; ?> <html> <head> </head> <body> <?php $a->func_a(); //I got in! to the display ?> </body> </html> I tried: b::func_b in func_a in class a, it gives the following error: Strict standards: Non-static method b::func_b() should not be called statically, assuming $this from incompatible context in a.class.php on line 12 I can hide thie error using: error_reporting(E_ALL ^ E_STRICT); This is not what I want; I want some "clean code". Is there a way to achieve this? Thanks in advance.
  5. Hi, Please consider the following image: As you can see, there are 4 divs being one big green, "test_div" and 3 small squre divs, "div_1"," div_2", "div_3". All I want to do is trying to trigger some mouse events with these. When the page is loaded, the following function is called and the above divs are basically all hidden: function hide_div() { document.getElementById("test_div").style.visibility = "hidden"; } and whenever the mouse cursor is over them another event is triggered with this function: function show_div() { document.getElementById("test_div")style.visibility = "visible"; } And html code(partial): <div id="test_div" onmouseover="show_div();" onmouseout="hide_div();"> <div id="div_1"></div> <div id="div_2"></div> <div id="div_3"></div> </div> All it does is simply hide-and-show function, but when I actully do that it does't work what I intended; when I put the cursor on "test_div"(green part only) it does show all the 4 divs correctly but as soon as I move the cursor to the one of three square divs(div_1, div_2 or div_3; didn't really matter) all the divs are gone and sometimes it blinks. I figured out that this is because onmouseover="show_div() is only triggered to "test_div" but apart from that I have no idea how to solve this. Pleae help!! thanks.
  6. Thanks for the reply. I mean I need a multiple strings searched with no sequential or single string. if the string given is as below: “In veterinary school we studied the brain of the hippopotamus. At that time most students stayed on the main campus, while I stayed on the hippocampus.” and I enter "campus school(bolded)" at the same time I want it to be true. I think preg_match searches one sting or adjacent strings only. Thanks
  7. Hi, Please see the code below: $string = 'I want to be a PHP geek!'; if (preg_match('/'. urldecode($_GET['no']) . '/i', $string)) //do something issue 1: When I search with parenthesis '(' I got the following error: Warning: preg_match(): Compilation failed: missing ) at offset 1 and with ')': Warning: preg_match(): Compilation failed: unmatched parentheses at offset 0 isseu 2: I want to search letter by letter; please consider the following snippet: $string = 'Do you want to be a PHP geek?'; preg_match('/php want/i', $string) ? $var = 'Cool': $var = 'Noooooo'; I want it to have me the $var "Cool". How can I get it done please? thanks for helping me.
  8. Hi, please consider the following simplified code: function show_ajax_result(str) { var request = new XMLHttpRequest(); request.open("GET", "query/query_search_product.php?sp=" + str + "&nocache="+new Date().getTime() , true); request.setRequestHeader('Content-type', 'application/x-www-form-urlencoded;charset=UTF-8;'); request.onreadystatechange = function() { if ((request.readyState != 4) || (request.status != 200)) { return; } document.getElementById("results").innerHTML = request.responseText; } request.send(null); } it works fine with pure English chars and numbers, but when it comes with non-English languages like Chinese, Japanese, Korean, Thai etc., some browser(ie9, ie10) doesn't pass the value to a server correctly. It works great with Chrome 23 and Firefox 16 and even Safari. And all the char values of the server and client are set to utf8. And without sending the data through XMLHttpRequest, query with non-English chars works perfectly. How can I have this solved please? Thanks.
  9. hi, I am using very simple ajax request as below: js file: function show_ajax_result(str) { var timer; clearTimeout(timer); var request = new XMLHttpRequest(); request.open("GET", "result.php?sp=" + str, true); request.onreadystatechange = timer = setTimeout(function() { if ((request.readyState != 4) || (request.status != 200)) { return; } document.getElementById("show_result").innerHTML = request.responseText; }, 400) request.send(null); } result.php: <?php $get = $_GET['sp']; if($get == 'test') echo 'I am here!'; else echo 'I'm not there yet!'; ?> They work perfectly. But as soon as I write the following code the request doesn't respond: $link = new mysqli("localhost", "root", "", "myDB"); I think its got to be something with db but I have no idea. Thanks in advance.
  10. This is somewhat simplifed codes in html. <form id="form" name="form" action="<?php echo $_SERVER['PHP_SELF'] ?>" method="post" enctype="multipart/form-data" > <input id="image" name="image" type="file" /> <input id="normal_post_var" name="normal_post_var" type="text" /> </form> and in the php file if(empty($_FILES['image']['name'])) $_FILES['image']['name'] = ''; if(empty($_POST['normal_post_var'])) $_POST['normal_post_var'] =''; echo $_FILES['image']['name']; echo '<br />'; echo $_POST['normal_post_var']; When the page is first loaded nothing wil be displayed. Once the page is fully loaded I choose an image file named 'image.png' and I input the value 'It is Cool' in the normal_post_var field. And I submit it and the result of course will be: image.png It is Cool And then I do nothing but clicking the submit button again will display the following: It is Cool the $_files value is gone. could you explain what's going on please?
  11. Hi, there. As far as I know the POST method holds the value if it is submitted consistently. But unlike the POST, $_files does not hold the value all along; when I click the submit button for the first time it DOES hold the value as I want, but if I click the submit once again the value it contains is just gone. Could you explain what's going on and how to prevent this from happening? thanks in advance.
  12. <?php if('00' == '000') echo 'weired'; ?> Please consider the code above. Strangely it echoes the word "weired". Also if('00' == '000000000000000') returns true and so forth. What is really going on? Thanks in advance By the way the php version is 5.3.9 on wampserver 2.2
  13. Hi, Is there a way to stream wide range of video file types like avi, mov, mpg, etc.? What I want to do is to allow users to upload any video files on the server and like wmv extension, I want other file types (especially mpg or mpeg extension) to be played as soon as the page loads. I am running my own server, and so if any server setting is required, I have full control of the server and I have already done with file uploading thing. I only need to implement video file streamming. Thanks.
  14. Please consider the following code: <?php // The file $filename = 'test.jpg'; // Set a maximum height and width $width = 500; $height = 340; // Content type //header('Content-type: image/jpeg'); // Get new dimensions list($width_orig, $height_orig) = getimagesize($filename); $ratio_orig = $width_orig/$height_orig; if ($width/$height > $ratio_orig) { $width = 500; } else { $height = 340; } // Resample $image_p = imagecreatetruecolor($width, $height); $image = imagecreatefromjpeg($filename); imagecopyresampled($image_p, $image, 0, 0, 0, 0, $width, $height, $width_orig, $height_orig); // Output imagejpeg($image_p, null, 100); ?> The code above works fine and also consider the following code which only added the html and body tags at the top and bottom: <html> <body> <?php // The file $filename = 'test.jpg'; // Set a maximum height and width $width = 500; $height = 340; // Content type //header('Content-type: image/jpeg'); // Get new dimensions list($width_orig, $height_orig) = getimagesize($filename); $ratio_orig = $width_orig/$height_orig; if ($width/$height > $ratio_orig) { $width = 500; } else { $height = 340; } // Resample $image_p = imagecreatetruecolor($width, $height); $image = imagecreatefromjpeg($filename); imagecopyresampled($image_p, $image, 0, 0, 0, 0, $width, $height, $width_orig, $height_orig); // Output imagejpeg($image_p, null, 100); ?> </html> </body> The latter code just displays bunch of strange text rather than image itself. How can I solve this problem so that I can see cool images again? Thanks.
  15. Hi, I am thinking of making a very very simple PHP chat application with ajax(for conversation window and keeping track of users' status). What I want is just concepts of the application, especailly the concepts of how to determine user is out of the browser(so the other people know this guy has left the chat room). And also I want to know which method is more used to process this sort of application between db and files. Thanks.
  16. Hi, I want to display some 'uploading...' image while uploading. I dont' need to have a prograss bar but just an image. Is there a way to achieve this please? Thanks.
  17. Hi, The question I'm about to ask is more like conceptual thing rather than actual code. Background: I am sure you probably ever saw a 'new' sign usually at the end when new posts are up on some forum. That usually lasts for certain amount of time( Although this php forum seems not working properly it does have a orange 'new' sign for every post). My question is how to implement the sign. I noramlly do the following easy steps: 1. When a new post is updated, current time in integer is stored in a database using time() function. 2. When the posts are shown(when I click PHP Cding Help link), it should determine if current time minus the time stored in DB is still new(say, the new sign is only valid for a day) show new sign otherwise do not show it. It's hard to explain what I am asking in writing; sorry about that. If you understand what my question is, I want to know the real world or better solution for this particular problem. Thanks
  18. Hi, please consider the following code: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Untitled Document</title> </head> <body> <?php function get_current_page() { $result = explode('?', $_SERVER['REQUEST_URI']); $str = $result[0]; $result = explode('/' ,$str); return $result[2]; } function get_prev_page() { return get_lid() - get_per_page(); } function get_next_page() { return get_lid() + get_per_page(); } function get_lid() { if(empty($_GET['lid'])) { return 0; } else { return $_GET['lid']; } } function get_per_page() { return 10; } function show_content() { $lid = get_lid(); $db_conn = new MySQLi('localhost', 'root', '', 'db'); $thumbnail = $db_conn->query("SELECT * FROM link ORDER BY no DESC LIMIT " . get_lid() .', 1'); while($row = $thumbnail->fetch_assoc()) { $link = $row['content']; echo $link . '<br />'; } } function show_link() { $lid = get_lid(); $db_conn = new MySQLi('localhost', 'root', '', 'db'); $thumbnail = $db_conn->query("SELECT * FROM link ORDER BY no DESC LIMIT " . get_lid() .', '. get_per_page()); echo '<a href="'. '?lid=' . get_prev_page() . '">' . 'Prev' .'</a> | '; //the condition that index gets negative values were NOT considered for simplicity of code; I have already done it in my real coding while($row = $thumbnail->fetch_assoc()) { $link = $row['no']; echo '<a href="'. '?lid=' . $lid++ . '">' . $lid .'</a> | '; } echo '<a href="'. '?lid=' . get_next_page() . '">' . 'Next' .'</a> | '; //the condition that index gets over max num_rows wwere NOT considered for simplicity of code; I have already done it in my real coding } ?> <?php get_next_page(); show_content(); ?> <p> </p> <?php show_link(); ?> </body> </html> And the DB structure is like so: DB name: db table name: link ---------------------------------------- no | content | ---------------------------------------- 1 | content 1 | ---------------------------------------- 2 | content 2 | ---------------------------------------- 3 | content 3 | ---------------------------------------- . . . ---------------------------------------- 30 | content 30 | ---------------------------------------- As you can see this code performs simple pagination. But it has one little problem. I want the link to be stable until I click the next or prev button. I mean if I click any link, the link just clicked becomes the first link. For example, on initial page load, the page might appear like this: -------------------------------- content 1 prev 1 2 3 4 5 6 7 8 9 10 next -------------------------------- But when I click on '3' the link changes as follows: ---------------------------------------- content 3 prev 3 4 5 6 7 8 9 10 11 12 13next ---------------------------------------- Whichever links are clicked I want these links stayed and moved by 10 when the prev or next button is clicked. Please HELP!! Thanks
  19. My point is; how does each paramater work? Does it work separately? My guess is they work Like this: $_GET['sid']; $_GET['tid']; So as far as I can guess they are two separate params and if sid points page1(of some website) tid indicates element1 (of page1 ) at the same time. Ahhhhhhhwwwwww I am getting confused. Could anyone please show me some kind of easy-to-understnad example?!! Thanks
  20. Hi, I am relatively comfortable using $_GET variable. But it comes with '&'(ampersand) I have no idea what is going on. I mean please see blow: http://www.example.com/example.php?sid=0&tid=2 Why does it need two(or more) ids and ampersand inbetween? Please explain what is going on. Thanks.
  21. Hi, is there any way to create a folder other than in the current folder? For example, if there are two folders being c:\a and c:\b and each folder will do the follwing: c:\a The php code that contains mkdir(getcwd() ."../b/photo1" , 0777) is run in this folder. c:\b In this folder the photo1 will be created. I tried to create the folder 'photo1' in c:\b which will fail. Unlike include('../../../photos.php');, the string part "../b/photo1" reads as it is. is there any way to achieve this please ? thanks
  22. Hi, Please consider the following chunk of code: <FORM NAME="nav"> <SELECT NAME="SelectURL" onChange= "document.location.href= document.nav.SelectURL.options[document.nav.SelectURL.selectedIndex].value"> <OPTION VALUE="" SELECTED>Please select a link: <OPTION VALUE="http://www.example.com"> Go to somewhere </SELECT> </FORM> From the code above, we have something like: document.location.href= document.nav.SelectURL.options[document.nav.SelectURL.selectedIndex].value. Could you please explain about the code after the "document.location.href=" elemnet by element? I can baerly understand why this code could link to somewhere. Thanks.
  23. Hi, Please consider the following snippet: <form enctype="multipart/form-data"> <input type="hidden" name="MAX_FILE_SIZE" value="1000000" /> <input name="uploadedfile" type="file" size="57" /> </form> <?php $target_path = "uploads/"; if(isset($_FILES['uploadedfile']['name'])) { $target_path = $target_path . basename( $_FILES['uploadedfile']['name']); } move_uploaded_file($_FILES['uploadedfile']['tmp_name'], $target_path) // additional code goes here... ?> I want to display a preview image just below the form as soon as I choose the image(in other words, clikcing 'browse...' button, select an image and click 'OK'). I think it should be done using ajax but I have no idea how to do. If there is any tutorial or piece of code for this, please HELP. Thanks.
  24. Hi, Please consider the following code: <form enctype="multipart/form-data" action="test.php" method="post"> <input name="uploadedfile" type="file" size="57" /> </form> From the code, is that possible to get a local drive's path of a file to be uploaded? For example, If I want to upload a file called 'a.jpg' and the file is in "C:\images". I want to get the whole path including the file name like "c:\images\a.jpg". Is this practically possible? Thanks.
  25. Please consider the following code: <form method="post"> Passwrod: <input tyep="text" name="name" /> <input type="submit" value="Ok" /> </form> $db_conn = new MySQLi('localhost', 'root', '', 'db'); $result = $db_conn->query("SELECT * FROM user_name"); $row = $result->fetch_assoc(); $fetched_name = $row['user_name']; $input_name = $_POST['user_name']; // Notice: Undefined index error if($fetched_name == $input_name) { header("Location: welcome.php "); } *This code simply fetches user names from the db and if the user name exists then it redirect to welcome.php page. When I run this code I get 'Notice: Undefined index:' error. Of course I can simply ignore this notice. But I don't want to have any error messages; I want to make my code CLEAN. Also I don't want to use the @ operator to hide the error. I wonder If there is any better solution for this. Thanks.
×
×
  • 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.