Jump to content

maxelct

Members
  • Posts

    37
  • Joined

  • Last visited

Profile Information

  • Gender
    Not Telling

maxelct's Achievements

Member

Member (2/5)

0

Reputation

  1. Hi I am using phpword to create a set of word documents - pupil reports. Its all working well except that I am using a html form to generate some text - which of course has minimal formatting - <p>, <h1>, <ol> etc I have been able to get the text into the field in my worddoc template but only if I put it through htmlspecialchars - - - $d=htmlspecialchars($descriptors["Number"]['H2'], ENT_HTML5); $templateProcessor->setValue('SpeakingDesc', $d); but of course I then end up with text like this: Is there a way to retain some measure of formatting for the text? Thanks
  2. that seems to work!!! I have been fiddling around for ages, and getting marked down on stackoverflow for being thick! I would like to understand how it works - So its doing $descriptors['Science' ]['P2']='text text text' - why doesn't it create a brand new 'Science array' for every level/descriptor each time - somehow it seems to cleverly know that the array science has already been created and add a new key=>value pair within the science array BTW thanks so much!
  3. Hi I have a data set that is coming from a db table like this science, p1, some text science, p2, some more text maths, p1, some text maths, p2, some more text All together that are going to be around 200 entries. These are subject descriptions/levels that will be written out into documents for pupils class reports. I am trying to create an array that looks like this: $descriptors = [ 'science' => [ 'p1' => 'text', 'p2' => 'more text' ], 'maths; => [ 'p1'=> 'text', 'p2'=> 'more text'. ] etc etc ]; At the moment i have an array $subject_list which goes 'Speaking', 'Science', 'Maths' etc I loop through the $subject_list and perform a query which returns the subject, the grade(the p1 bit) and the text How do I turn this data in the 2d array shown above. I am trying to put an array with a name into an array but I can't figure it out. This is as far as I could get $desc[]=array('subject'=>$sub, 'grade'=>$row['grades'], $row['descriptor']); but this is creating an array which has about 200 arrays in it - all with 3 items - not what I want How can I do this please
  4. phppdocx looks interesting. But I think I need something that doesn't involve licensing (long story). Our docs have to be saved into a folder, and then personal comments have to be added into.
  5. Thanks - hadn't come across that option in my research. It all needs to be automatic - the user is going to be generting 100s (potentailly) of different docs/reports.
  6. Hi I am running a WAMP local server with php 5.4.12. I have to create a number of word.docx files from a database. My research suggests lots of possibilities. My forms are not going to be complex, but I do need to be able to save / print them Using headers wont give me much control I don't think. I know this is a bit of a vague question - but could anyone advise on which approach might be best for me? I'd really appreciate it Edward
  7. Thanks guys - realized I had the syntax wrong for getting the array element. All works now!
  8. Hi I have a form which contains 4 select boxes (amongst the usual input types) Here's an example <div class="formElement"><p class="formText">Are you a tenant:</p><input class="checkbox" type="checkbox" name="resid[0]" value="is-tenant" /><div class="clearer"></div></div> <div class="formElement"><p class="formText">Are you a landlord:</p><input class="checkbox" type="checkbox" name="resid[1]" value="is-landlord" /><div class="clearer"></div></div> Now, I want to make these stick so that they are checked if the user presses submit, but forgets to fill in say their name etc Here's what I tried <div class="formElement"><p class="formText">Are you on benefits:</p><input class="checkbox" type="checkbox" name="resid[0]" value="is-on-benefits" <?php if ($_POST["resid[0]"]=="is-on-benefits" ){ echo 'checked="yes" ';} ?>/><div class="clearer"></div></div> which didn't work... along with <div class="formElement"><p class="formText">Are you on benefits:</p><input class="checkbox" type="checkbox" name="resid[0]" value="is-on-benefits" <?php if ((isset($_POST["resid[0]"]) ){ echo 'checked="yes" ';} ?>/><div class="clearer"></div></div> and putting !empty instead of isset. I guess I am doing something wrong? Can anyone help please Thanks Edward
  9. The function is quite long (to my mind) and I didn't want to annoy anyone. Sorry. Fact is I didn't know what to do after this point - what tests to try and run. As you no doubt can tell I am on the edge (and way over) what I really know. // function: resize_image (string $source_image, string $target_image, int $target_width, int $target_height[, boolean $crop_position]) // purpose: resizes an image using the parameters supplied // parameters: [1] $source_image (string) -> the filename and path of the source file // [2] $target_image (string) -> the filename and path of the target file // [3] $target_width (int) -> the width of the target file (set as false for this to be calculted by the height) // [4] $target_height (int) -> the height of the target file (set as false for this to be calculted by the width) // [5] $crop_position (string) -> (optional) if the image is to be centre cropped (square), values are: left, right, top, bottom, centre // [6] $quality (int) -> (optional) the jpeg quality // returns: whether the image creation succeeded or failed function resize_image ($source_image, $target_image, $target_width, $target_height, $crop_position = false, $quality = 75) { // set the memory limit higher and the execution time higher for the script as large // attachments may be processed ini_set('memory_limit', '32M'); ini_set('max_execution_time', '60'); $return_var = false; // initialise the return variable // get the source file type $source_type = get_mime_type($source_image); // get the target file type if (is_numeric(strpos(strtolower($target_image), 'jpg')) || is_numeric(strpos(strtolower($target_image), 'jpeg'))) { // if the type is jpeg $target_type = 'image/jpeg'; } elseif (is_numeric(strpos(strtolower($target_image), 'gif'))) { // if the type id gif $target_type = 'image/gif'; } // get the dimensions of the source image and check whether the file is valid if (list($source_width, $source_height) = getimagesize($source_image)) { // calculate the dimensions of the new photo // if there is no width set then calculate from the ratio of the source image and // the height dimension if (!$target_width) { $target_width = ($source_width / $source_height ) * $target_height; } // if there is no height set then calculate from the ratio of the source image and // the width dimension if (!$target_height) { $target_height = ($source_height / $source_width ) * $target_width; } // if the target filetype is a jpeg, create a truecolour image if ($target_type == 'image/jpeg') { //edward echo ' [b] $target_type='.$target_type.'[/b]'; // create an empty image in memory with the target's dimensions //$target_file = imagecreatetruecolor($target_width, $target_height); if($target_file = imagecreatetruecolor($target_width, $target_height)){ echo '[b] imagecreatetruecolor was true[/b]'; }else{ echo '[b] imagecreatetruecolor was false[/b]'; }; } else { // otherwise create a pallete based image // create an empty image in memory with the target's dimensions $target_file = imagecreate($target_width, $target_height); } // if the source image is a jpeg then load it if ($source_type == 'image/jpeg') { echo ' [b] source_type='.$source_type.'[/b]'; // load the source image as a jpeg from disk into memory // edward $source_file = imagecreatefromjpeg($source_image); if($source_file = imagecreatefromjpeg($source_image)){ echo '[b] imagecreatefromjpeg was true[/b]; }else{ echo '[b] imagecreatefromjpeg was false[/b]'; }; } elseif ($source_type == 'image/gif') { // otherwise load the source image as a gif from disk into memory $source_file = imagecreatefromgif($source_image); } // preset the source x and y positions of the output image $source_x = 0; $source_y = 0; // copy the source width and height to some other variables used in calculation $calc_width = $source_width; $calc_height = $source_height; // if it's specified that the image should be cropped if ($crop_position) { // calculate the source & target ratios $source_ratio = $source_width / $source_height; $target_ratio = $target_width / $target_height; // calculate the other dimension if ($source_ratio > $target_ratio) { $source_width = ($target_width / $target_height ) * $calc_height; } else { $source_height = ($target_height / $target_width ) * $calc_width; } // depending on which crop position is selected, the calculations will be // done to extract the required part switch ($crop_position) { case 'top': $source_x = ($calc_width - $source_width) / 2; $source_y = 0; break; case 'bottom': $source_x = ($calc_width - $source_width) / 2; $source_y = $calc_height - $source_height; break; case 'left': $source_x = 0; $source_y = ($calc_height - $source_height) / 2; break; case 'right': $source_x = $calc_width - $source_width; $source_y = ($calc_height - $source_height) / 2; break; default: $source_x = ($calc_width - $source_width) / 2; $source_y = ($calc_height - $source_height) / 2; break; } } // if a jpeg is to be created if ($target_type == 'image/jpeg') { // RESIZE the image with the parameters specified imagecopyresampled($target_file, $source_file, 0, 0, $source_x, $source_y, $target_width, $target_height, $source_width, $source_height); // remove the image of the source file from memory imagedestroy($source_file); // create a jpeg file on disk from the newly created image in memory and write to disk $return_var = imagejpeg($target_file,$target_image, $quality); // remove the image of the target file from memory imagedestroy($target_file); // if a gif file is to be created } elseif ($target_type == 'image/gif') { // RESAMPLE the image with the parameters specified imagecopyresized($target_file, $source_file, 0, 0, $source_x, $source_y, $target_width, $target_height, $source_width, $source_height); // remove the image of the source file from memory imagedestroy($source_file); // create a gif file on disk from the newly created image in memory and write to disk $return_var = imagegif($target_file,$target_image); // remove the image of the target file from memory imagedestroy($target_file); } } return $return_var; // return the status of the function }
  10. Hi - still really need help on this - please
  11. Thanks again. I have found the resize_imgae function and have started to see if the varoius functions within it are working. Here's the output create [b] $target_type=image/jpeg[/b] [b] imagecreatetruecolor was true[/b] What I think might be odd (!) is that source_type test and the imagecreatefromjpeg doesn't seem to generate true of false. Or am I missing the point? // function: resize_image (string $source_image, string $target_image, int $target_width, int $target_height[, boolean $crop_position]) : : ///////////////////////////////////////// added a test here?????????????? // if the target filetype is a jpeg, create a truecolour image if ($target_type == 'image/jpeg') { //edward echo '[b] $target_type='.$target_type.'[/b]'; // create an empty image in memory with the target's dimensions //$target_file = imagecreatetruecolor($target_width, $target_height); if($target_file = imagecreatetruecolor($target_width, $target_height)){ echo '[b]imagecreatetruecolor was true[/b]'; }else{ echo '[b] imagecreatetruecolor was false[/b]'; }; // if the source image is a jpeg then load it ///////////////////////////////////////// is this odd?????????????? if ($source_type == 'image/jpeg') { echo ' [b] source_type='.$source_type.'[/b] '; // load the source image as a jpeg from disk into memory // edward $source_file = imagecreatefromjpeg($source_image); if($source_file = imagecreatefromjpeg($source_image)){ echo '[b] imagecreatefromjpeg was true[/b]'; }else{ echo '[b] imagecreatefromjpeg was false[/b]'; }; } elseif ($source_type == 'image/gif') { // otherwise load the source image as a gif from disk into memory $source_file = imagecreatefromgif($source_image); } : : : }
  12. Hi - just got a "Help" message from the hosting company. They say nothing has changed on their servers and suggested: Please can you try adding this line to your scripts 'configuration'file and retest: putenv("MAGICK_THREAD_LIMIT=1"); Sadly didn't make any difference though... Just thought I'd add it to the mix
  13. Thanks - yes, three black images in the correct folder and with the correct names are created. Here are alll the error messages: Warning: imagecopyresampled(): supplied argument is not a valid Image resource in /websites/LinuxPackage02/...admin/php/nslib_php/nslib_image.php on line 133 Warning: imagedestroy(): supplied argument is not a valid Image resource in /websites/LinuxPackage02/.../admin/php/nslib_php/nslib_image.php on line 136 Warning: imagecopyresampled(): supplied argument is not a valid Image resource in /websites/LinuxPackage02/...admin/php/nslib_php/nslib_image.php on line 133 Warning: imagedestroy(): supplied argument is not a valid Image resource in /websites/LinuxPackage02/.../admin/php/nslib_php/nslib_image.php on line 136 Warning: imagecopyresampled(): supplied argument is not a valid Image resource in /websites/LinuxPackage02/.../admin/php/nslib_php/nslib_image.php on line 133 Warning: imagedestroy(): supplied argument is not a valid Image resource in /websites/LinuxPackage02/.../admin/php/nslib_php/nslib_image.php on line 136
  14. Good comments! Its a bespoke system that appears to have been developed (perhaps with libraries) about 6 or 7 years ago. I added in the error line and it showed this; Array ( [name] => 14032010216.jpg [type] => image/jpeg [tmp_name] => /tmp/phpC1jCtW [error] => 0 [size] => 65469 )
×
×
  • 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.