Jump to content
Larry Ullman's Book Forums

Necuima

Members
  • Posts

    359
  • Joined

  • Last visited

  • Days Won

    7

Everything posted by Necuima

  1. Hi, This question does not apply directly to this book, so far anyway, but I'm wondering if someone can give me advice on the coordinates for an HTML imagemap area. I have been experimenting with an imagemap with a number of selectable areas defined via the standard map and area tags. Does anyone know if the coordinate values can somehow be adjusted to take account of varying viewport dimensions? The code following works for a selectable area on an image map on my localhost (Windows) PC. But if I change the size of the viewport, the selectable area changes and in some cases disappears altogether. Any advice will be most appreciated and thank you in anticipation. <div> <img src="../images/product_header_test.jpg" title="Image Title" id="product_header_image" usemap="#product_image"> <?php // calculate the coordinate values from the width of the wrapper in pixels // assume screen width of 1920 pixels just for the sake of this exercise // first the 'raw' rectangle coordinates (obtained from 'paint') $top_left_raw_x = 273; $top_left_raw_y = 160; $bottom_right_raw_x = 375; $bottom_right_raw_y = 183; $factor = 1650/1920; // this yields a pretty good answer but was derived at by trial and error $top_left_x = (int) $top_left_raw_x * $factor; $top_left_y = (int) $top_left_raw_y * $factor; $bottom_right_x = (int) $bottom_right_raw_x * $factor; $bottom_right_y = (int) $bottom_right_raw_y * $factor; // this does not work if you resize the screen!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! echo <<<EOT <map name="product_image"> <area shape="rect" coords="$top_left_x,$top_left_y,$bottom_right_x,$bottom_right_y" href="$home" alt="Home" target="_self"> </map> EOT;
  2. Hi Ken, I am not familiar with wamp but have xampp on my development PC. My understanding is that when you key in http://localhost/ecom1 the browser looks for either index.html or index.php within the ecom1 directory. I wonder if the problem is the absence of either of these? Cheers.
  3. Hi Larry and Hartley-san, After carefully examining the documentation and code samples that came with PHPDOCX PRO, I discovered that there are two ways of creating a MS WORD document which contains a table - one is via converting html to WORD, which is the way that I used above and which gave me the errors also described above, and the other way is to create the WORD table 'natively' using PHPDOCX's table functionality. FYI I finally figured out how to do it the 'native' way and it works a treat. I was led to my solution by very carefully examining some of the code samples supplied and basing my code on the code structures in the samples. I have to say that PHPDOCX is very feature-rich and even with my OK table, I have only scratched the surface of its capabilities. Thanks again for your interest and suggestions. Cheers from Oz.
  4. Hi Larry, thanks for the tip re pandoc - I will check it out. Hi too Hartley-san - it's not an infinite loop - because it eventually stops, but I will keep checking. Thanks to both of you! Cheers from Oz.
  5. Hi Larry and Hartley-san, Thanks for the suggestion. I did this, both as a dump to the screen and also writing the $html variable to a .doc file with fwrite. Echo-ing to the screen causes the program to go into some sort of loop, but writing the $html variable to the .doc file works just fine. And when I do this (as well as the PHPDOCX stuff), it works perfectly!! So I'm guessing that it's something to do with the PHPDOCX functionality. I'm using the 'convert html to .docx' approach but I see from their documentation that there is another way to create a table in PHPDOCX - I might give that a try too. Again, thanks for your thoughts and cheers from Oz.
  6. Hi, I am experiencing a problem that I don't understand. I am retrieving records from a MySQL database. In each record there is a pointer to a jpg image file which is stored in a directory on the server. I build a long string of html in a variable, including the retrieved jpg images. This html variable is then fed into PHPDOCX to generate a MS WORD document. Randomly the images in the WORD document are not the correct image for that database record. Let me try and clarify: let's call a record retrieved from the database record 'a' which points to a jpg image file, say imga.jpg. The next record retrieved from the database, let's call it record 'b' which points to a jpg image file, say imgb.jpg. Most of the time these will display correctly in the generated MS WORD document, but seemingly randomly, sometimes both record 'a' and record 'b' will show the imgb.jpg image. I have inserted a clearstatcache(TRUE, $file_name)which seems to have reduced the number of these image errors but not all of them. Does anyone have any ideas - if you do they will be most appreciated. Here's some of my code: while (list(...lots of fields, $file_name) = mysql_fetch_row($r1)) {..... html table header stuff... // now a 'data' line $icon_file_name = substr($file_name, 0, -4); // chop off the .jpg $icon_file_name = "../../dir1/dir2/" . $icon_file_name . "_icon.jpg"; $html .= "<tr valign='top'> ...other table row data... <td align=\"left\"><img width='100%' src='$icon_file_name'></td> </tr>"; clearstatcache(TRUE, $icon_file_name); ...etc... My environment is:. Windows 7 Home Premium 64 bit . Internet Explorer 10 . Firefox 22.0 . Dreamweaver CS5 as the text editor . Flex 4 via FlashBuilder 4 . PHPDOCX PRO 3.7 . XAMPP for Windows 1.8.3 which comprises: .. Apache 2.4.4 .. PHP 5.5.3 .. MySQL 5.6.11 .. phpMyAdmin 4.0.4 Note: I can't use the mysqli functions as they are not supported by the production hosting site. Any assistance/ideas will be most appreciated. Thanks and Cheers.
  7. Hi Larry, Thanks for getting back to me. Yes, in the end I left both the checks in the admin section and the BASE_URL check in the 'public-view' section. Cheers from Oz.
  8. Hi, I recently restructured a website along the modularization lines (page 44 onwards). The content modules all start with a check to see if the BASE_URL constant has been defined and redirect the user if it has not been defined. This is clear and works just fine in the visitor-accessible part of the site. In the administration part of my website, the modules also check to make sure that an administrator is using the script via a check to a session set up like page 82 onwards. I am having trouble with 'headers already sent' and understand why this is happening and know how to fix that. But my question is do I need both the BASE_URL constant check as well as the administrator/session check in the admin content scripts? There are no financials in the website and also no sensitive data in the database though I need to ensure that non-administrators cannot use the admin scripts. Your thoughts/advice will be welcomed. Cheers from Oz.
  9. Hi Hartley-san, yes, I've already started doing that - thanks for the tip. I also have 2 new books from the 'Missing Manuals' series - one on HTML5 and the other on CSS3 - and I see from the index that media queries is covered. If you are currently in Ohio, I shall wish you "Good Night" :-) Cheers from Oz.
  10. Wow - this is a terrific solution!! FYI I 'got around' the problem described above by making the file references within the header.inc file absolute but your solution is much more elegant! A related function in the js file is to adjust text font sizes also based on the available width - do you have an elegant solution for that as well? Here's that code... function adjust_font_sizes () { var mc_w = $('#wrapper').width(); // alert('Main Col Width is ' + mc_w); if (mc_w >= 1000) { var f_s = (1000 / 8) + '%'; $('.table_entry_text').css('fontSize', f_s); var f_s2 = (1000 / 9) + '%'; $('.about_button').css('fontSize', f_s2); var f_s3 = (1000 / 7.5) + '%'; $('h3').css('fontSize', f_s3); var td_size = (1000 / 4) + 'px'; $('td').css('width', td_size); } else { var f_s = (mc_w / 8) + '%'; $('.table_entry_text').css('fontSize', f_s); var f_s2 = (mc_w / 9) + '%'; $('.about_button').css('fontSize', f_s2); var f_s3 = (mc_w / 7.5) + '%'; $('h3').css('fontSize', f_s3); var td_size = (mc_w / 4) + 'px'; $('td').css('width', td_size); } } Thanks again, Hartley-san! Cheers from Oz.
  11. Hi, I wasn't sure whether to post this in this forum or the "Modern JavaScript" forum so apologies if I've got it wrong. I am trying to modularise a website that is already in production and works fine, but the modularisation approach in chapter 2 looks very appealing. In one part of the website I have the index.php 'controller' module which includes other modules on a one by one basis as needed. The structure of index.php is as per chapter 2 of the book. Every time the index.php module is invoked, I include header.inc.htm which has within it an invocation of a small JS routine which just adjusts the width of the displayed website based on the width of the available viewport. What happens is that the first time index.php includes say module_a.php the width adjustment works perfectly. Then after having done its thing, module_a.php calls module_b.php via the index.php controller passing it a parameter that module_b needs. However, even though the exact same header.inc.htm module gets included when module_b.php is included by index.php, the JS routine does not fire and the width of the website display does not get adjusted. I've attached some of the code; first the header.inc.htm file which invokes the JS adjust-wrapper_size() routine. As you can see, I tried both 'document ready' and window load' but the problem appears both ways. <!DOCTYPE html> <head> <title><?php echo $page_title; ?></title> <link rel="stylesheet" type="text/css" href="./css/the_css_file.css" media="screen" /> <script type="text/javascript" src="../jQuery/jquery_1.5.2.min.js"></script> <script type="text/javascript" src="../js/the_js_file.js"></script> <script type="text/JavaScript"> // window.onload(function() $(document).ready(function() { adjust_wrapper_size(); // to stop it from being too big! }); // end document ready function $(window).resize(function() { adjust_wrapper_size(); // to stop it from being too big! }); // end window resize function </script> </head> Now the code in module_a which calls module_b (add_cv_2) via index.php; .... $group_name = urlencode($_POST['cv_group']); $url = BASE_URL . "index.php?p=add_cv_2&cvgroup=$group_name"; if (!headers_sent($filename, $linenum)) { header("Location: $url"); exit(); } ...... Now the code within index.php... ..... case 'add_cv_2': $page = 'module_b.php'; $page_title = "The appropriate title"; break; ..... And finally the JS routine: function adjust_wrapper_size() { var s_w = window.innerWidth || document.documentElement.clientWidth || document.body.clientWidth || document.width; // to cater for all browsers // alert('Window/Screen width = ' + s_w); if (s_w > 1000) { $('#wrapper').css('width', 1000); } else { // screen < 1000 - use available screen $('#wrapper').css('width', s_w); } } My environment is: . Windows 7 Home Premium 64 bit . Internet Explorer 10 . Firefox 22.0 . Dreamweaver CS5 as the text editor . Flex 4 via FlashBuilder 4 . XAMPP for Windows 1.8.3 which comprises: .. Apache 2.4.4 .. PHP 5.5.3 .. MySQL 5.6.11 .. phpMyAdmin 4.0.4 Any assistance will be most appreciated. Thanks, and Cheers from Oz.
  12. It seems that the overhead of the DB approach is not warranted in my case. Many thanks for the advice. Cheers from Oz.
  13. Hi Hartley-san, this looks very interesting. Can this be modified to store the session information in a database instead of in a directory? See Larry's book page 82.... Cheers from Oz.
  14. Hi, After a bit of sweat and tears, I finally managed to get a FLEX/AIR native process to work and Larry encouraged me to post it in case it is of interest. A bit of background: Since the publication of Larry's book, Adobe released version 4.6 of FlashBuilder as well as the 4.6 SDK. This and subsequent versions support a capability called 'native process' which enables a FLEX/AIR application to call another application which would normally run in a DOS box (Windows) or the equivalent in a Mac. This capability enables you to put a user-friendly front end (UI) onto an application that would normally run in a DOS box. Larry will shortly post my code which is an example of using native process to invoke ImageMagick to resize jpg image files - one by one. ImageMagick is available free to download from the 'Net and is a very powerful image processor - it can resize images as well as do heaps of other neat things with image files. So in a sense my example only scratches the surface of ImageMagick's capabilities, nevertheless I have found image resizing useful. Anyone trying this will have to edit one line in the mxml code and that is the exact location of the ImageMagick convert.exe file in their environment. I have left quite a few comments in the code which I hope will be of value. I found a couple of traps along my native process learning journey - firstly the xml file has to have the extended profile added to it - see the bottom of the xml file. Secondly, if you are using FlashBuilder to create the file which will subsequently be transformed by AIR into an executable, you need to export release build it as a 'signed native installer' otherwise you will get errors if you try to export release build it as a 'signed AIR package' (it took me ages to get that bit right!). Re the resizing functionality: the user first selects a jpg image file to be resized from the user's desktop or PC. Then it needs the new size parameter to be filled in (in pixels). The value will be the new image width for a landscape image or the new image height for a portrait image - in either case the image aspect ratios are preserved. Then the UI asks you for the image quality value to use for the processed image - the higher the quality parameter the larger the resultant image file will be. I have found that a quality parameter value of about 75 to 80 still yields good image quality with smaller file sizes. Once the processing is complete, the new image file is written out to the user's desktop/PC with a 'resized' file name suffix (in the same directory as the input image). Note that the usual pixilation problems will appear if you try to increase the size of the image, as the program is written to only enable the selection of a jpg file. Though this could be changed to select a lossless image file format but you'd need to change the file selection filter. Note: this application runs on the desktop (so that it can access the file system) thus is not a browser-Flash application. As mentioned above, Larry will post the code in case anyone wants to try this. Cheers from Oz!
  15. I am using post for the form and now, with the addition of a specific form action, it works fine. (It is index.php that gets the 'get'). Many thanks for the guidance. Cheers!
  16. Yes, I see what you are getting at... At the moment the action is not set at all so the module just calls itself - I will try it with the action set to index.php and the appropriate GET parameter value. Thanks for you thoughts.
  17. Hi Hartley-san, Let me try and clarify... On page 57 Larry makes the comment that index.php is the "only page that should ever be loaded in the Web browser". Index.php then includes configuration and header stuff and then includes a page (at a time) from the /modules/ folder which does the actual work. Let's say that the module which is included uses php redux, e.g., after say displaying a form, the module calls itself to process that form. When it calls itself it doesn't go through the index.php control structure and thus is missing all the config and header logic which is part of the index.php structure. So maybe the modularistaion structure is incompatible with an included module which then calls itself to process form data via php redux. Again, thanks for any thoughts/guidance on this matter. Cheers from Oz.
  18. Hi, I have been experimenting with the modularised approach as per chapter 2 and really like the concept. However, one of my sites has lots of PHP redux in the admin scripts which update a database and upload lots of selected files. Can one use PHP redux and the modularised approach, wherein all accesses are channelled through a controller/index.php script, together? The problem that I am 'admiring' is that when a script calls itself (via PHP redux), the modularised approach would seem to require that that call be channelled through the controlling script, index.php. Can this be done or are the two approaches incompatible? Thanks in anticipation for any thoughts/guidance. Cheers from Oz.
  19. Even though you can set the constants from $_SERVER data, Hartley-san and Larry are right in that it is better to hard-code the values because if one of your scripts is surreptitiously invoked, and that script is not in the site's highest-level directory, the automatic setting of the constant values will give you incorrect results. So do it as the book says! Cheers from Oz.
  20. More 'fiddling' yielded the following for the URI: $base_URI = $_SERVER['DOCUMENT_ROOT'] . dirname($_SERVER['SCRIPT_NAME']) . '/'; define('BASE_URI', $base_URI); I think that I have 'fiddled' enough now :-) Note that this is only for my XAMPP localhost environment. Cheers
  21. Hi Hartley-san, Thanks for your feedback. In Larry's example (page 49) he tests which environment the script is executing in and sets the constants accordingly. That is what I was fiddling with - to generate the correct constant values in either case. Yes, maybe my 'fiddling' is a bit unnecessary but I was just experimenting to see if I could get the constants set dynamically:-) I will also check out the PHP functions you recommended - thanks. Cheers from Oz.
  22. As an experiment, I tried to see if I could generate the values for the constants and somewhat to my surprise I found that I could. Here's an example: $base_URI = $_SERVER['DOCUMENT_ROOT']; $script_filename = $_SERVER['SCRIPT_NAME']; // find the last slash and then truncate the string at that point $slash_location = strrpos($script_filename, '/'); // finds the last slash $script_filename = substr($script_filename, 0, $slash_location); // chop off the script name $base_URI .= $script_filename . '/'; define('BASE_URI', $base_URI); As I was not able to find any examples of setting a constant in this way on the Internet, I was quite wary, but it seems to work OK. Any traps to be aware of? Note1: I tested the value of the constant with echo '<p>URI is ' . constant("BASE_URI") . '</p>'; Note2: the process would be a little different in the production environment as some of the $_SERVER elements are different in the hosted production environment, though there are array values from which the constant values could be generated and a number of them are the same array key names. Thanks for your interest and Cheers from Oz.
  23. Hi Hartley-san, Thanks for this. I checked and my hosting company uses IIS. I was able to get the full path info via $_SERVER['DOCUMENT_ROOT']. I first echo'd out the whole $_SERVER array and from that I saw that the DOCUMENT_ROOT array element had the full path. Which begs the question, when setting the constant, should it/could it just be set from this $_SERVER array value? Thus if the hosting company changed this for any reason, the value of the constant would automatically be updated? Cheers from Oz.
  24. Looking at your initial post again, as Larry has mentioned on a number of occasions, for most of us very different skills/abilities are needed to design things than subsequently implementing them. Design is a very creative pursuit whereas implementation requires I think different skills like very logical/analytical thinking. If you can do both equally well, then you have exceptional talents. Good luck with your choices! Cheers from Oz.
×
×
  • Create New...