How does uploading of images work within Geodesic programs?

Problem:

How does uploading of images work within Geodesic programs?



Solution:

Untitled Document

How does uploading images work within Geodesic Programs?

All of the configurations for the image upload process are found in one page within the admin tool:
AD CONFIGURATION > IMAGES CONFIGURATION
Or
LISTING CONFIGURATION > FILE UPLOAD
Depending on the Geodesic script you have purchased.

1: CHOOSING AND UPLOADING THE IMAGES

When the images are submitted by the image submission form the server/php receives the images and places them in a temporary folder configured by the server and PHP. The very first consideration when uploading images is the time it takes for the images to get to the server. Once the client clicks the submit button in the images form the images they have chosen within the image upload form begin to travel to your server/domain over the Internet.

There are a couple considerations to keep in mind with images traveling to your server/domain from a client. The first is the PHP timeout. PHP has a maximum execution time configuration designed to stop runaway computation processes. All hosts configure a maximum time that any PHP process can have to do what it needs to do. This is a precaution in place by the server to stop individual scripts from taking up all the resources on the server when it may look like the process may never stop. The time starts ticking on this process once the client clicks the submit button on the image upload form. The PHP execution timeout may actually last longer than the same amount of time in real time as the server may only count the time the server actually spends on the process.

The second consideration is the speed of connection between your client and you server/domain. The connection between the two is only as fast as the slowest portion of that connection. The slowest part of that connection is usually the clients Internet connection. This connection could be a slow "dialup" connection. In high traffic times the slowest portion of the pipe between your server/domain and your client could be your server's connection to the Internet.

The first possible error in the image uploading process is that the server timeout could be reached before all of the images are uploaded to the server. The error will look something like:

Fatal error: Maximum execution time of 30 seconds exceeded in /local/home/user/mysite/classes/classified_sell_class.php on line ###

Time is necessary to upload images to your server and the maximum execution time within PHP could affect this process. If the maximum execution time is exceeded the problem could be the Internet connection and/or the size of images uploaded to your site. When the maximum execution time is reached two things could happen. Your client will usually see a PHP error message stating that the maximum execution time has been exceeded if your host allows or has set PHP errors to be displayed...this is the usual case. Or your clients could see a blank white page if your host has PHP error display turned off within the PHP configuration file (php.ini file). When PHP is configured to not display errors the client browser is not displayed any errors if there happen to be any while processing. If this is the case the error could be found in your domains error log.

2: PLACING IMAGES IN THE TEMP DIRECTORY

Once all of the images uploaded reach your server the images are placed in a temporary directory that is predetermined within the internal configurations of the server. Placing images within the temporary directory provides the next possible error that could happen in the image upload process. This is a very rare error and only happens when the server was not configured correctly to handle image uploads. The actual process running on the server handling the image upload process must have the correct "rights" to place those uploaded images into the temporary directory. This type of error usually does not happen with larger hosts. It usually only happens on server configured individually for a specific purpose. When this error happens the problem is at the server level...not within PHP. Errors within PHP are usually displayed to the browser. Errors at the server level are hardly ever displayed to the browser and they usually result in a blank white page displayed to the browser. Again not a very common error but one that can be considered once all others possible errors have been eliminated.

A possible error in this part of the image upload process is "user rights" at the server level usually with an error displayed in the page. The error should look something like:

Warning: imagejpeg(): Unable to open '/home/mysite/public_html/classifieds/images/123456.jpg' for writing in /home/mysite/public_html/classifieds/classes/classified_sell_class.php on line ####

To fix you will need to change the rights to the "image" directory using your ftp program. The permissions for this directory should be set to where the script can write images to this directory (this is usually "CHMODed" to 777 on most hosts). This can be done through the ftp program or through the host management tool your host provides

3: PLACING IMAGE INFORMATION WITHIN VARIABLES ACCESSIBLE WITHIN THE GEO SCRIPT

The information about the images uploaded is put into a variable within the PHP working environment called $_FILES. The Geodesic script then takes the information from the $_FILES array variable and begins processing the uploaded images and media into the Geodesic classified ad or auction system.

After the images are fully uploaded to the server the PHP environment "starts" the Geodesic script. The Geodesic script starts working its way through the $_FILES array that contains all the information about the files uploaded to the site. The script pulls information about each image one at a time and processes each image in turn working its way through the $_FILES array.

4: FILE SIZE CHECK

The first check of the files uploaded is the file size check. Each image is checked to make sure that is does not exceed the maximum file size set within the "max file size" set within the images configuration page of the admin tool. If the file size exceeds the maximum set the script will pass this particular image without any further computation and proceed to the next image in the $_FILES array. The image will not be attached to the listing currently being inserted by the client.

The possible error in this step of the image upload process is that the files uploaded could be larger than the max file size allowed by the script. This error is usually handled within the script and displays a general upload failure error within the image upload form if all uploaded images exceeded the max file size limit...or the approval screen with those images that did not exceed the max file size limit displayed.

5: CHECK TO SEE IF IMAGE IS WITHIN THE ACCEPTED FILE TYPES LIST

The next check run is to see if the image is within the accepted files list the admin has set within the allowed upload file type admin tool. The file type is checked by looking at the mime-type within the $_FILES array set for each particular uploaded file against the mime-type entered within the allowed file type admin tool. This is another place where an uploaded image will be rejected by the script. The mime-type for the uploaded image is embedded within the header of the file and is set within program that created the image or media. There are sometimes a few different mime-types for the same file type and you may have a client with one of these different mime-type headers yet have the same file type extension (for example ".jpg" at the end of the filename). When you have a client with unique/different mime-type the only way to possibly get the file allowed within the system is to get a copy of the file attempted by the client. You will need to manually insert the file into the allowed file type admin tool to allow the script to extract the new mime-type from the file and add that specific mime-type to the allowed file types list.

The possible problem in this step of the image upload process could be that a file type may not be allowed by the script. No error is displayed but the "not accepted" file(s) are not shown on the next screen.

Once the mime-type has been determined to be within the allowed mime-types list the script then checks to see how the script should treat the uploaded file type. If the files mime-type is determined to not be within the accepted file types set within the admin processing on that file is stopped and the script moves onto the next file uploaded. This file will not be attached to the listing currently being created by the client.

6: PROCESSING THE IMAGE ACCORDING TO FILE TYPE

Within the allowed upload file type admin tool the admin can determine how the file is treated when displayed on the client side within an auction or classified ad. The "image" file types like the jpeg or gif can be uploaded and the images displayed directly within the html with no problems. Other file types cannot be displayed directly within html efficiently. With these file types the admin can set an icon to display within the details of the auction or classified ad instead of the actual file itself. With these file types the client wishing to view these files can click on the icon and they will be prompted to download the image. If the file type uploaded is determined to be represented by an icon that file is then immediately uploaded to its final destination within the "images" directory. A reference to that uploaded file and the representative icon are then placed within the database in connection with the ad being inserted.

7: CHECKING FILENAME AVAILABILITY

Before any file is moved into the "images" directory/folder the script attempts to find a filename not currently used within the images directory. The script randomly creates a 7 digit number and attempts to find a file by that name within the images directory. If no file of the same name is found this 7 digit number becomes the final filename for the uploaded file within the "images" directory.

8: PROCESSING IMAGE FROM TEMP DIRECTORY TO IMAGES DIRECTORY

If the file type uploaded is not represented by an icon and also not a jpeg file type the script immediately moves that file directly into the "images" directory. With file types that are not to be represented by an icon the image dimensions are discovered by the script and compared to the lead image or thumbnail dimensions set within the images configuration to determine what the thumbnail size dimensions should be. With the image file types that are not a jpeg type they are copied directly to the "images" directory with no thumbnail image created. PHP comes installed with GD Library within it. This is the image library used by PHP to create images and by the Geo script to create thumbnail images displayed while browsing and in the listing detail. This image library will only create jpeg images from other jpeg images. It cannot be used to resize other file types within Geo scripts. Other file types will most likely be added when they become more common image file types. But as a practice around the Internet 99% of images uploaded by clients is the jpeg image type. This is the image type that is most used by digital cameras.

One possible error in this step of the image upload process is that the server path to the images directory could be set wrong within the Geodesic Admin tool. You could see an error like:

Warning: copy(/home/mysite/public_html/classifieds/images/234567.jpg): failed to open stream: No such file or directory in /home/mysite/public_html/classifieds/classes/classified_sell_class.php on line ####

To fix this error look at the error produced closely. The way to correct this type of error within the error message itself. If you notice php displays the correct path to the php file where the error occured. This error should point to the /classes/classified_sell_class.php file. Everything in that path before "/classes" is the correct server path to your domain on that server. Look at the first part of the error between the parentheses after "copy". That is the server path you currently have set here within the admin tool:

AD/AUCTION CONFIGURATION > IMAGES CONFIGURATION > "directory path to images directory"
OR
LISTING CONFIGURATION > PHOTO UPLOAD SETTINGS > "directory path to images directory"

depending on your version of our software. Make sure the server path in the last part of the error message matches the path to what you have set in the first part of the error message.
A possible error in this part of the image upload process is "user rights" at the server level usually with an error displayed in the page. The error should look something like:

Warning: imagejpeg(): Unable to open '/home/mysite/public_html/classifieds/images/123456.jpg' for writing in /home/mysite/public_html/classifieds/classes/classified_sell_class.php on line ####

To fix you will need to change the rights to the "image" directory using your ftp program. The permissions for this directory should be set to where the script can write images to this directory (this is usually "CHMODed" to 777 on most hosts). This can be done through the ftp program or through the host management tool your host provides

The full size image height and width dimensions are compared to each other to determine the ratio between the two. This ratio is used to determine the height and width of the thumbnail image dimensions. The image is then moved by the script to the "images" directory to the filename found. Information about the image is then saved within the database that contains location information about the uploaded image, thumbnail dimensions and full size image dimensions.

If the lead image dimensions are larger than the thumbnail settings the lead image dimensions are the maximum thumbnail settings used when creating the thumbnail image. If the thumbnail dimensions are larger than the lead image dimensions the thumbnail dimension dimensions are used in creating the thumbnail image. If the lead image setting is not used the thumbnail width and height become the maximum dimensions of the thumbnail image.

Once the thumbnail size settings have been determined the script checks to see if the image is a jpeg type image. If it is a jpeg type of image the script will attempt to create a "thumbnail" sized image using the dimensions determined above. The script uses the GD image library that is configured to work with almost all PHP installations. To create the thumbnail image the script passes in the original image, the dimensions of the image to create from the original image and the quality setting to be used by GD library when creating that image. The resulting thumbnail image is then moved to the images directory as well as the full size image.

The last possible error in uploading image is usually caused at the server level. To process the full size images into thumbnail images requires quite a bit of working space on the server. The geodesic script, GD Image Library, PHP, the uploaded images, working space for GD Library to create thumbnail images and the thumbnail images themselves must all be within the current working memory space at one time. Many hosts have been setting the allowing maximum space for any PHP to work in at any one time to 8MB. This seems to be a new default setting within the latest PHP installations. With all of the space needed to create thumbnails the 8MB memory limit can be exceeded quite easily. You can usually narrow down "blank white" screen errors to this error if you can find that you do not have errors when uploading a small image but get the error on a larger image. Our internal experience shows that the problem size threshold rests between 50 and 100KB images. Most images smaller will not cause an error while most images larger will cause the "white screen" error. The only way to fix this error is to contact your host to ask that the max memory limit setting within PHP be changed to a larger value. We have found that 12 MB never causes a problem.

If you see an error displayed to the browser in this step the error will say something like:

Fatal error: Allowed memory size of xxxxxxxx bytes exhausted (tried to allocate xxxx bytes) in home/mysite/public_html/classifieds/classes/classified_sell_class.php on line xxxx

If the image is not a jpeg file type the script simply moves the file untouched to its final place within the images directory determined within the admin tool.

Once the images are moved the script then saves all the information about the images within the database with information that will tie the image to the ad or auction it should be attached to.


Properties ID: 000120   Views: 2255   Updated: 4 years ago