Photoshop web design - PHP SOLUTIONS: DYNAMIC WEB DESIGN MADE EASY name

PHP SOLUTIONS: DYNAMIC WEB DESIGN MADE EASY name to each file as it s uploaded. By placing move_uploaded_file() at this point, you can use the value of $name to generate a unique name for the uploaded file and its thumbnail. Rather than show you how to do it step by step, I ll just give you a few hints. The getNextFilename() function from the previous chapter automatically generates a new filename. It takes three arguments: the target folder (directory), the filename s prefix, and the file type. The target directory is UPLOAD_DIR, the filename s prefix is stored in $name, and the file type is stored in $type. However, $type is currently a number, so you need to convert it to a string. If you store the new name in $newName, you can use it in combination with basename() to build the name for the thumbnail so that the original image and thumbnail have the same number. Refer back to PHP Solution 4-3 for an explanation of how to use basename(). The changes involved are quite simple and involve fewer than 20 lines of code. The solution is in upload_both_new.php and create_both_new.inc.php in the download files. The new code is clearly marked and commented. Transferring your test files to a remote server If you have been testing these files locally, the only changes that you need to make when deploying them on a remote server are to the definitions of UPLOAD_DIR and THUMBS_DIR. Use a fully qualified path to each folder (directory). Don t forget that the necessary read, write, and execute permissions need to be set on the upload folders. Also make sure that the path to any include files reflects your site structure. Change the values of MAX_HEIGHT and MAX_WIDTH if you want the resized images to be larger or smaller than 120 90 pixels. Summary Although this is a relatively short chapter, it covers a lot of ground and brings together techniques from Chapters 4, 6, and 7, in combination with the PHP image manipulation functions. To get the most out of working with PHP, it s important to understand the flow of a script so that you can incorporate solutions from other scripts. It would be a major project to attempt to build from scratch a form that uploads an image, makes a scaled- down copy, and gives both of them new names. However, breaking the task down into discrete sections, as done here, makes it a lot easier. It also gives you the opportunity to reuse code from one project in another, saving time and effort. There are many other things you can do with the GD extension, including adding dynamic text to images and generating bar charts. For more details, take a look at Chapter 8 of PHP 5 Recipes: A Problem-Solution Approach by Lee Babin and others (Apress, ISBN: 1-59059-509-2).
Searching for affordable and proven webhost to host and run your servlet applications? Go to Linux Web Hosting services and you will find it.

Leave a Reply