Permalink
Browse files

Added more allowed file types and code clean-up.

  • Loading branch information...
1 parent 550ae9f commit 8b5c18c7710f1750ec00f7ba27ae2c216a449b47 U-ONLY4TES-F74E9A\Administrator committed Mar 11, 2011
Showing with 20 additions and 16 deletions.
  1. +16 −12 README
  2. +2 −1 js/uploader.js
  3. +2 −3 uploader.php
View
28 README
@@ -1,29 +1,33 @@
How to install:
-1. Place the "image-gallery" folder at your web server document root;
+1. First of all, make sure PHP web server is installed;
-2. Create an empty folder "temp" underneath "image-gallery". It must have 777 permissoin. This is where all the uploaded images will reside.
+2. Place the "image-gallery" folder at PHP web server document root;
-3. In "uploader.html", line 7 - 34, modify the path to the right infusion code. Fluid source code will be linked in as external in the future.
+3. Create an empty folder "temp" underneath "image-gallery" and grant it 777 permissoin. This is where all the uploaded images will reside.
-4. access via (just an example): http://localhost/image-gallery/uploader.html
+4. The scripts, lines that need to be modified with the right path to infusion source code.
+ uploader.html - line 7 - 34
+ js/uploader.js - line 12, 21, 22
+
+5. That's all. Now access via (just an example): http://localhost/image-gallery/uploader.html
How it looks like:
-This image gallery uploader demo is composed by 2 parts: the multi-file uploader at left and an viewer at right.
+This image gallery uploader demo is composed by 2 parts: the multi-file uploader at left and an image viewer at right.
The work flow:
-1. When "upload" button is clicked: the html page sends the upload request along with a session token. This session token is a unique 13 characters long string that is generated by javascript. It helps the php server to distinguish the upload requests from different users.
+1. When "upload" button is clicked: the html page sends the upload request to the server along with a session token. This session token is a unique 13-character string that is generated by javascript. It helps the php server to distinguish the upload requests from different clients.
-2. Once the PHP server receives the uploaded image, it creates a new folder that is named as the session token from the client under folder "temp", places the images into the new folder, then sends back the message which is the url to the uploaded image. The client retrives the url and adds it to the viewer.
+2. Once the PHP server receives the uploaded image, it looks up in the "temp" directory for the sub-directory that is named after the sent-in session token. If the sub-directory does not exist, the script creates it. The uploaded images are placed into the sub-directory, then the server sends back the url of the uploaded image. The client retrives the url and adds it to the image viewer.
-3. If anything goes wrong during upload at PHP server, for instance, no file is received, session token is not provided, etc, the server returns a error message with http status code 400. The client displays the error on the page along with the name of the corresponding file that is uploaded.
+3. If anything goes wrong at PHP server, for instance, no file is received, session token is not provided, etc, the server returns a error message with http status code 400. The client displays the error on the page along with the name of the corresponding file.
A few constraints performed at PHP server:
-1. The server removes the temporary folders that stay inactive for one hour. This is performed in uploader.php as the first thing whenever it's called.
+1. The server removes the temporary folders that are inactive for one hour. This is performed in uploader.php as the first thing whenever it's called.
-2. For security reason, the server only allows the upload of these file types: jpg, gif, png, tif
+2. For security reason, the server only allows the upload of these file types: jpg, jpeg, gif, png, tif, tiff
-3. When the file with the same name is uploaded twice, append a unique incremental number to the file name.
- for instance, "1.jpg" is renamed to "1-1.jpg" at the second upload.
+3. When the file with the same name is uploaded twice, a unique incremental number is appended to the second file name to ensure the uniqueness of each uploaded image.
+ for instance, "1.jpg" will be renamed to "1-1.jpg" at the second upload.
Questions:
1. in uploader.html, line 37, "styles.css" is linked in at "the uploader demo" section, should it be moved to the top of the script to be together with other .css
View
@@ -26,7 +26,8 @@ var demo = demo || {};
},
queueSettings: {
// Set the uploadURL to the URL for posting files to your server.
- uploadURL: "uploader.php?session="+sessionID
+ uploadURL: "uploader.php?session="+sessionID,
+ fileTypes: "*.gif;*.jpeg;*.jpg;*.png;*.tiff;*.tif"
},
listeners: {
onFileSuccess: function (file, responseText, xhr){
View
@@ -4,7 +4,7 @@
include("include/vitals.inc.php");
// The constants
-$allowed_file_extensions = array('gif', 'png', 'jpg', 'tif'); // The array of allowed file extensions: gif, png, jpg, tif
+$allowed_file_extensions = array('gif', 'png', 'jpg', 'jpeg', 'tif', 'tiff'); // The array of allowed file extensions: gif, png, jpg, tif
$secs_to_timeout = 3600; // The seconds to keep the uploaded images
$temp_dir = 'temp/';
@@ -16,10 +16,9 @@
// 2. wether session id is provided;
// 3. wether the file extension is allowed;
// 4. the existence of $temp_dir.
-debug_to_log($_FILES);
+
// 1. Return error if there is no file received
if (count($_FILES) == 0) {
- debug_to_log("no file received");
return_error("No file is received at server.");
exit;
}

0 comments on commit 8b5c18c

Please sign in to comment.