PHP SOLUTIONS: DYNAMIC WEB DESIGN MADE EASY To (Web site developers)

PHP SOLUTIONS: DYNAMIC WEB DESIGN MADE EASY To understand what has happened, cast your mind back to Chapter 6. The switch statement checks the value of $_FILES[’image’][’error’]. If it s 0, it means that the upload succeeded. The original script moved the temporary upload file to its target destination. The include command simply replaces that part of the script with the code that creates the thumbnail. Further improvements You now have a powerful mini-application that automatically resizes images on upload, but what if you want to preserve the original image as well? Nothing could be simpler. The page containing the upload form already defines the upload folder as UPLOAD_DIR, so you simply need to move the temporary upload file (currently referred to as $original) with move_uploaded_file(). PHP Solution 8-4: Saving the uploaded original and scaled-down version Continue working with the same files. Alternatively, use create_thumb.inc.php and upload_thumb02.php from the download files. The finished scripts are in create_both.inc.php and upload_both.php. 1. Open upload_thumb.php and save a copy as upload_both.php. 2. In upload_both.php, locate the line that includes the script that creates the scaled- down image. It should be around line 35, and looks like this: include(’../includes/create_thumb.inc.php’); Change it like this and save the page: include(’../includes/create_both.inc.php’); 3. Open create_thumb.inc.php and save a copy in the includes folder as create_both.inc.php. 4. In create_both.inc.php, locate the section of code that strips the extension from the filename (around line 22), and insert the new code highlighted in bold: // strip the extension off the image filename $imagetypes = array(’/.gif$/’, ‘/.jpg$/’, ‘/.jpeg$/’, ‘/.png$/’); $name = preg_replace($imagetypes, ‘’, . basename($_FILES[’image’][’name’])); // move the temporary file to the upload folder $moved = @ move_uploaded_file($original, . UPLOAD_DIR.$_FILES[’image’][’name’]); if ($moved) { $result = $_FILES[’image’][’name’].’ successfully uploaded; ‘; $original = UPLOAD_DIR.$_FILES[’image’][’name’]; } else {
Visit our web design programs services for an affordable and reliable webhost to suit all your needs.

Leave a Reply