GENERATING THUMBNAIL IMAGES $result (Web hosting solutions) = ‘Problem uploading ‘.$_FILES[’image’][’name’].’;
GENERATING THUMBNAIL IMAGES $result = ‘Problem uploading ‘.$_FILES[’image’][’name’].’; ‘; } // create an image resource for the original The new code moves the temporary upload file to the upload folder and saves it with its original name. The move_uploaded_file() function returns a Boolean true or false, so by assigning the result to $moved, you can tell whether the operation is successful. If it is, a suitable message is created, and the pathname of the uploaded file is reassigned to $original. This is very important, because move_uploaded_file() immediately discards the temporary uploaded file. So, from this point onward, the original file is now the one that has just been saved on the server. If $moved is false, there s no point in reassigning the value of $original, which still points to the temporary upload file. This means you still have a chance of creating the thumbnail, even if the main upload fails. I ve inserted the error control opera tor (@) in front of move_uploaded_file() to prevent the display of PHP error mes sages, so it s important to create a custom error message indicating what the problem is. 5. The outcome of the upload operation uses the same variable, $result, as the section of the script that creates the resized image, so you need to make sure that the second outcome is added to the first. Do this with the combined concatenation operator (.=) toward the end of the script, by inserting a period in front of the equal sign like this: if ($success) { $result .= “$thumb_name created”; } else { $result .= ‘Problem creating thumbnail’; } As it stands, the script gives you the chance to salvage at least part of the oper- ation if the main upload fails. If you don t want a thumbnail without the main image, move the last four lines of new code in step 4 immediately below the code in step 5. This brings the thumbnail creation script inside the first half of the conditional statement, so it runs only if $moved is true. 6. Save create_both.inc.php, and load upload_both.php into a browser. Test it by selecting an image on your local computer and clicking Upload. The original image should be copied to the upload_test folder and a scaled-down version to the thumbs subfolder. You may be wondering why I inserted the new code in step 4 in that particular location, because it doesn t really matter when you move the uploaded file, as long as the script can create an image resource from it. The answer is because the script currently overwrites existing images of the same name. For a really robust solution, you need to assign a unique 229
Note: If you are looking for cheap and reliable webhost to host and run your mysql application check mysql web server services.