Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

1. Fixed the bug in the installation script (install.sh) that it wipe…

…s out the scripts that have infusion library path to be replaced. 2. In the sake of providing the testers an easy way to produce the server error, the server now rejects the file that has already been uploaded. 3 Removed the mistankely commited scripts with suffix "_new".
  • Loading branch information...
commit ec37cf2fcd4490cc2ee25b1786e9e71129c108fe 1 parent 391151e
Cindy Li authored
View
7 README
@@ -6,7 +6,7 @@ How to install:
git clone git://github.com/cindyli/image-gallery.git
cd image-gallery
- ./install.sh -- Note that install.sh asks for the input of the path to infusion library
+ ./install.sh -- Note that install.sh asks for the path to your local infusion library
3. That's all. Now access via (just an example): http://localhost/image-gallery/uploader.html
@@ -21,12 +21,11 @@ The work flow:
3. If anything goes wrong at PHP server, for instance, no file is received, session token is not provided, invalid file extension, or temp/ folder does not exist, 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 folder created for each session that are inactive for over an hour. This is performed in uploader.php as the first thing whenever it's called.
+1. Removes the temporary folder created for each session that are inactive for over an 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, jpeg, gif, png, tif, tiff
-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.
+3. Rejects the same file that has already been uploaded.
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
31 include/vitals.inc.php
@@ -113,37 +113,6 @@ function clean_history($directory, $secs_to_live) {
}
/**
- * Ensure the uniqueness of the file name, $file_name, in the directory $directory.
- * If the file with the same name already exists in the directory, attach suffix "-N" to the name.
- * N is a incremented number calculated base on the existing file names.
- * For instance, if "1.jpg" already exists, return "1-1.jpg"; if "1-1.jpg" already exists, return "1-2.jpg"
- * @param string $file_name the file name to check
- * string $directory the folder that the file resides
- * @return string, a unique file name
- */
-function get_unique_name($file_name, $directory){
- if (file_exists($directory.$file_name)) {
- $prefix = substr($file_name, 0, strrpos($file_name, '.'));
- $extension = substr($file_name, strrpos($file_name, '.') + 1);
-
- $pos_of_dash = strrpos($prefix, '-');
-
- if ($pos_of_dash > 0) {
- // The renamed file with the counter already exists. Increment the counter in the file name by 1
- $str_before_dash = substr($prefix, 0, $pos_of_dash);
- $int_after_dash = intval(substr($prefix, $pos_of_dash + 1));
- $rtn = $str_before_dash.'-'.($int_after_dash+1).'.'.$extension;
- } else {
- // The first renamed file
- $rtn = $prefix.'-1.'.$extension;
- }
- return get_unique_name($rtn, $directory);
- } else {
- return $file_name;
- }
-}
-
-/**
* Return error msg with http status code 400
* @access public
* @param string err_string the error message
View
6 install.sh
@@ -12,7 +12,9 @@ mkdir temp
chmod 777 temp
# Set the correct infusion path
-sed "s#\[INFUSION_PATH\]#"$infusion_path"#g" uploader.html > uploader.html
-sed "s#\[INFUSION_PATH\]#"$infusion_path"#g" js/uploader.js > js/uploader.js
+sed "s#\[INFUSION_PATH\]#"$infusion_path"#g" uploader.html > uploader_new.html
+mv uploader_new.html uploader.html
+sed "s#\[INFUSION_PATH\]#"$infusion_path"#g" js/uploader.js > js/uploader_new.js
+mv js/uploader_new.js js/uploader.js
exit
View
20 js/uploader.js 100755 → 100644
@@ -1,13 +1,12 @@
/*global jQuery*/
/*global fluid*/
-/*global demo*/
var demo = demo || {};
(function ($, fluid) {
demo.initUploader = function () {
- var sessionID = Math.random().toString(16).substring(2);
-
+ var sessionID = Math.random().toString(16).substring(2);
+
// Load the Uploader's template via AJAX and inject it into this page.
var templateURLSelector = "[INFUSION_PATH]/src/webapp/components/uploader/html/Uploader.html .fl-uploader";
$("#uploader-contents").load(templateURLSelector, null, function () {
@@ -24,24 +23,21 @@ var demo = demo || {};
}
}
},
- queueSettings: {
+ 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){
+ onFileSuccess: function (file, responseText, xhr) {
// the server code passes the new image URL in the responseText
$('#image-space').append('<img src="' + responseText + '" alt="' + file.name + '" class="image-frame" />');
},
- onFileError: function (file, error, status, xhr){
- $('#server-error').append(file.name + " - " + xhr.responseText + "<br />");
+ onFileError: function (file, error, status, xhr) {
+ $('#server-error').append(file.name + " - " + xhr.responseText + "<br />");
}
}
});
});
};
-})(jQuery, fluid);
-
-
-
+})(jQuery, fluid);
View
47 js/uploader_new.js
@@ -1,47 +0,0 @@
-/*global jQuery*/
-/*global fluid*/
-/*global demo*/
-
-var demo = demo || {};
-
-(function ($, fluid) {
- demo.initUploader = function () {
- var sessionID = Math.random().toString(16).substring(2);
-
- // Load the Uploader's template via AJAX and inject it into this page.
- var templateURLSelector = "aa/src/webapp/components/uploader/html/Uploader.html .fl-uploader";
- $("#uploader-contents").load(templateURLSelector, null, function () {
-
- // Initialize the Uploader
- fluid.uploader(".flc-uploader", {
- components: {
- strategy: {
- options: {
- flashMovieSettings: {
- flashURL: "aa/src/webapp/lib/swfupload/flash/swfupload.swf",
- flashButtonImageURL: "aa/src/webapp/components/uploader/images/browse.png"
- }
- }
- }
- },
- queueSettings: {
- // Set the uploadURL to the URL for posting files to your server.
- uploadURL: "uploader.php?session="+sessionID,
- fileTypes: "*.gif;*.jpeg;*.jpg;*.png;*.tiff;*.tif"
- },
- listeners: {
- onFileSuccess: function (file, responseText, xhr){
- // the server code passes the new image URL in the responseText
- $('#image-space').append('<img src="' + responseText + '" alt="' + file.name + '" class="image-frame" />');
- },
- onFileError: function (file, error, status, xhr){
- $('#server-error').append(file.name + " - " + xhr.responseText + "<br />");
- }
- }
- });
- });
- };
-})(jQuery, fluid);
-
-
-
View
4 uploader.html 100755 → 100644
@@ -65,12 +65,12 @@
<div id="demo-notes">
1. Your session will stay active for an hour. After one hour, all the uploaded images will be erased from the server.<br />
- 2. Allowed uploaded file types (case insensitive): jpg, png, gif, tif
+ 2. Allowed uploaded file types (case insensitive): jpg, png, gif, tif
</div>
<script type="text/javascript">
demo.initUploader();
- </script>
+ </script>
</body>
</html>
View
21 uploader.php
@@ -8,7 +8,7 @@
$secs_to_timeout = 3600; // The seconds to keep the uploaded images
$temp_dir = 'temp/';
-// Removed all the folders that are older than 3600 seconds
+// Remove all the folders that are older than 3600 seconds
clean_history($temp_dir, $secs_to_timeout);
if (isset($_REQUEST['isSingleUploader']) && $_REQUEST['isSingleUploader']) {
@@ -19,10 +19,11 @@
}
// Error checkings:
-// 1. wether the file is received;
-// 2. wether session id is provided;
-// 3. wether the file extension is allowed;
-// 4. the existence of $temp_dir.
+// 1. whether the file is received;
+// 2. whether session id is provided;
+// 3. whether the file extension is allowed;
+// 4. whether $temp_dir exists;
+// 5. whether the file has been uploaded.
// 1. Return error if there is no file received
if (count($_FILES) == 0) {
@@ -52,7 +53,7 @@
exit;
}
- // Find or even create the image folder for this round of upload
+ // Find or even create the image folder, if it does not exist, for this round of upload
$image_folder = $temp_dir . $_REQUEST['session'].'/';
if (!file_exists($image_folder) && !mkdir($image_folder)) {
return_error('Cannot create image folder <span style="font: bold">'.$image_folder.'</span>.', $return_err_in_html);
@@ -60,10 +61,12 @@
}
// END OF error checking
- // Get a unique file name in case the file with the same name has been uploaded before
- $file_name = get_unique_name($file_name, $image_folder);
-
$destination = $image_folder.$file_name;
+ // 5. Return error if the file has been uploaded
+ if (file_exists($destination)) {
+ return_error($file_name.' has already been uploaded.', $return_err_in_html);
+ exit;
+ }
// Copy the uploaded file into the image folder
move_uploaded_file($file_data['tmp_name'], $destination);
View
76 uploader_new.html
@@ -1,76 +0,0 @@
-<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
-<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
- <head>
- <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
- <title>Uploader</title>
-
- <link rel="stylesheet" type="text/css" href="../infusion/src/webapp/framework/fss/css/fss-reset.css" />
- <link rel="stylesheet" type="text/css" href="../infusion/src/webapp/framework/fss/css/fss-layout.css" />
- <link rel="stylesheet" type="text/css" href="../infusion/src/webapp/components/uploader/css/Uploader.css" />
-
- <!-- Fluid and jQuery Dependencies -->
- <script type="text/javascript" src="../infusion/src/webapp/lib/jquery/core/js/jquery.js"></script>
- <script type="text/javascript" src="../infusion/src/webapp/lib/jquery/ui/js/jquery.ui.core.js"></script>
- <script type="text/javascript" src="../infusion/src/webapp/framework/core/js/jquery.keyboard-a11y.js"></script>
- <script type="text/javascript" src="../infusion/src/webapp/lib/jquery/plugins/scrollTo/js/jquery.scrollTo.js"></script>
- <script type="text/javascript" src="../infusion/src/webapp/lib/swfobject/js/swfobject.js"></script>
- <script type="text/javascript" src="../infusion/src/webapp/lib/swfupload/js/swfupload.js"></script>
-
- <script type="text/javascript" src="../infusion/src/webapp/framework/core/js/Fluid.js"></script>
- <script type="text/javascript" src="../infusion/src/webapp/framework/core/js/DataBinding.js"></script>
- <script type="text/javascript" src="../infusion/src/webapp/framework/core/js/FluidIoC.js"></script>
- <script type="text/javascript" src="../infusion/src/webapp/framework/core/js/FluidDocument.js"></script>
- <script type="text/javascript" src="../infusion/src/webapp/framework/core/js/FluidView.js"></script>
- <script type="text/javascript" src="../infusion/src/webapp/framework/enhancement/js/ProgressiveEnhancement.js"></script>
-
- <!-- Uploader dependencies -->
- <script type="text/javascript" src="../infusion/src/webapp/components/uploader/js/Uploader.js"></script>
- <script type="text/javascript" src="../infusion/src/webapp/components/uploader/js/FileQueue.js"></script>
- <script type="text/javascript" src="../infusion/src/webapp/components/progress/js/Progress.js"></script>
- <script type="text/javascript" src="../infusion/src/webapp/components/uploader/js/FileQueueView.js"></script>
- <script type="text/javascript" src="../infusion/src/webapp/components/uploader/js/FlashUploaderSupport.js"></script>
- <script type="text/javascript" src="../infusion/src/webapp/components/uploader/js/Flash9UploaderSupport.js"></script>
- <script type="text/javascript" src="../infusion/src/webapp/components/uploader/js/HTML5UploaderSupport.js"></script>
- <script type="text/javascript" src="../infusion/src/webapp/components/uploader/js/DemoUploadManager.js"></script>
-
- <!-- The Uploader demo -->
- <link rel="stylesheet" type="text/css" href="css/styles.css" />
-
- <script type="text/javascript" src="js/uploader.js"></script>
- </head>
- <body>
-
- <!-- Basic upload controls, used when JavaScript is unavailable -->
- <form action="uploader.php" method="post" enctype="multipart/form-data" class="fl-progEnhance-basic" id="single-file-uploader">
- <input type="hidden" name="isSingleUploader" value="1">
-
- <p>Use the Browse button to add a file, and the Save button to upload it.</p>
- <input name="fileData" type="file" />
- <input class="fl-uploader-basic-save" type="submit" value="Save"/>
- </form>
-
- <div id="uploader-contents">
- <!-- The Uploader's template will be injected via AJAX into this container. -->
- </div>
-
- <div id="image-viewer">
- <!-- The container to display all the uploaded images. -->
- <h2>Uploaded images:</h2>
- <div id="image-space"></div>
- </div>
-
- <div id="server-error">
- <!-- The returned server error message will be displayed in this container. -->
- </div>
-
- <div id="demo-notes">
- 1. Your session will stay active for an hour. After one hour, all the uploaded images will be erased from the server.<br />
- 2. Allowed uploaded file types (case insensitive): jpg, png, gif, tif
- </div>
-
- <script type="text/javascript">
- demo.initUploader();
- </script>
-
- </body>
-</html>
Please sign in to comment.
Something went wrong with that request. Please try again.