[MOD] MultiUpload
- This mod enables the users to add multiple files to a category at once.
- The images will get name and index, ie. "My pet", "My pet 2", "My pet 3",...
- for 4images 1.7.1
The best way to install this is to use the provided files, which give the changes compared to original installation of 4 images.
FILES
Files to be modified: (please take a backup copy of all of these!)
-categories.php //settings
-categories.html //To access the new action
-member.php //functionality (ie. looping the default upload method as long as required)
New files:
-member_multiuploadform.html //this is a simplified template for the multiupload
-two buttons... multiupload.gif, and multiupload_off.gif, I attached some as samples.
*NEW* I have included the clean versions of all these files to this post. They contain nothing more than the multiupload mod, it should be easy to integrate from there.
Recommended/required MODS
-auto thumbnailer and auto resizer MODs are highly recommended
-I also use my own EXIF reader and autorotate(according to the EXIF) MODs... these are yet to be released...
INSTALL
------------------------------------
I. SETTING THE VARIABLES
categories.php:
1.
AFTER:
$upload_button = "<img src=\"".get_gallery_image("upload_off.gif")."\" border=\"0\" alt=\"\" />";
ADD:
$multiupload_button = "<img src=\"".get_gallery_image("multiupload_off.gif")."\" border=\"0\" alt=\"MultiUpload images to this Gallery\" />";
2.
AFTER:
$upload_button = "<a href=\"".$upload_url."\"><img src=\"".get_gallery_image("upload.gif")."\" border=\"0\" alt=\"\" /></a>";
ADD:
$multiupload_url = $site_sess->url(ROOT_PATH."member.php?action=multiuploadform&".URL_CAT_ID."=".$cat_id);
$multiupload_button = "<a href=\"".$multiupload_url."\"><img src=\"".get_gallery_image("multiupload.gif")."\" border=\"0\" alt=\"Upload Multiple files\" /></a>";
3.
AFTER:
"upload_button" => $upload_button,
ADD:
"multiupload_button" => $multiupload_button,
categories.html
4.
REPLACE:
{upload_button}
BY:
{upload_button} {multiupload_button}
II. FUNCTIONALITY
member.php
1.
REPLACE:
if ($action == "uploadimage") {
BY:
if ($action == "uploadimage" || $action=="multiuploadimage") {
2.1
REPLACE:
if (!$error) {
// Start Upload
include(ROOT_PATH.'includes/upload.php');
$site_upload = new Upload();
// Upload Media file
if (!empty($HTTP_POST_FILES['media_file']['tmp_name']) && $HTTP_POST_FILES['media_file']['tmp_name'] != "none") {
$new_name = $site_upload->upload_file("media_file", "media", $upload_cat);
if (!$new_name) {
$msg .= (($msg != "") ? "<br />" : "")."<b>".$lang['file_upload_error'].": ".$new_name."</b><br />".$site_upload->get_upload_errors();
$uploaderror = 1;
}
}
else {
$new_name = $remote_media_file;
}
BY:
if (!$error) {
//MULTI FILE UPLOAD
$fileext="";
while(isset($HTTP_POST_FILES['media_file'.$fileext]))
{
include_once(ROOT_PATH.'includes/upload.php');
$site_upload = new Upload();
// Upload Media file
if (!empty($HTTP_POST_FILES['media_file'.$fileext]['tmp_name']) && $HTTP_POST_FILES['media_file'.$fileext]['tmp_name'] != "none") {
$new_name = $site_upload->upload_file('media_file'.$fileext, "media", $upload_cat);
if (!$new_name) {
$msg .= (($msg != "") ? "<br />" : "")."<b>".$lang['file_upload_error'].": ".$new_name."</b><br />".$site_upload->get_upload_errors();
$uploaderror = 1;
}
}
elseif($action=="uploadimage") {
$new_name = $remote_media_file;
}
else
{
$new_name = "";
break;
}
2.2 * new *
REPLACE:
elseif ($config['auto_thumbnail'] == 1 && !empty($HTTP_POST_FILES['media_file']['tmp_name']) && $HTTP_POST_FILES['media_file']['tmp_name'] != "none" && !$uploaderror) {
BY:
elseif ($config['auto_thumbnail'] == 1 && !empty($HTTP_POST_FILES['media_file'.$fileext]['tmp_name']) && $HTTP_POST_FILES['media_file'.$fileext]['tmp_name'] != "none" && !$uploaderror) {
3.1 (NOW START REPLACING ALL THE includes and requires INSIDE THIS ACTION by include_once and require_once)
REPLACE:
require(ROOT_PATH.'includes/image_utils.php');
BY:
require_once(ROOT_PATH.'includes/image_utils.php');
3.2 do this to change the image names to have index
REPLACE:
if ($direct_upload) {
$sql = "INSERT INTO ".IMAGES_TABLE."
(cat_id, user_id, image_name, image_description, image_keywords, image_date, image_active, image_media_file, image_thumb_file, image_download_url, image_allow_comments".$additional_field_sql.")
VALUES
($cat_id, ".$user_info['user_id'].", '$image_name', '$image_description', '$image_keywords', $current_time, $image_active, '$new_name', '$new_thumb_name', '$image_download_url', $image_allow_comments".$additional_value_sql.")";
BY:
$imgname = ($fileext!="")?"$image_name $fileext":$image_name;
if ($direct_upload) {
$sql = "INSERT INTO ".IMAGES_TABLE."
(cat_id, user_id, image_name, image_description, image_keywords, image_date, image_active, image_media_file, image_thumb_file, image_download_url, image_allow_comments".$additional_field_sql.")
VALUES
($cat_id, ".$user_info['user_id'].", '$imgname', '$image_description', '$image_keywords', $current_time, $image_active, '$new_name', '$new_thumb_name', '$image_download_url', $image_allow_comments".$additional_value_sql.")";
4.
REPLACE:
include(ROOT_PATH.'includes/search_utils.php');
BY:
include_once(ROOT_PATH.'includes/search_utils.php');
5.
REPLACE:
include(ROOT_PATH.'includes/email.php');
BY:
include_once(ROOT_PATH.'includes/email.php');
6.
REPLACE:
$msg .= $lang['image_add_success'].": <b>".stripslashes($image_name)."</b> (".$new_name.")";
BY:
$msg .= $lang['image_add_success'].": <b>".stripslashes($image_name)."</b> (".$new_name.")<br>";
7. (almost over... )
REPLACE:
$content .= "<table border=\"0\" align=\"center\">\n<tr>\n<td>\n".$media."\n</td>\n</tr>\n</table>\n";
}
else {
$action = "uploadform";
$sendprocess = 1;
}
}
else {
$action = "uploadform";
$sendprocess = 1;
}
}
if ($action == "uploadform") {
BY:
$content .= "<table border=\"0\" align=\"center\">\n<tr>\n<td>\n".$media."\n</td>\n</tr>\n</table>\n";
$good=1;
}
else {
//Atleast 1 multifile succeeded.
if(count($HTTP_POST_FILES) && $good==1)
{
$action = "multiuploadform";
break;
}
else
{
$action=($action=="multiuploadimage")?"multiuploadform":"uploadform";
$sendprocess = 1;
break; //break the while if any image upload fails
}
}
$fileext=($fileext=="")?2:$fileext+1;
}//end while
}//end if
else
{
$action = "uploadform";
$sendprocess = 1;
}
}//end upload action
//Show the form
if ($action == "uploadform" || $action == "multiuploadform") {
8. to parse the correct html...
REPLACE:
$content = $site_template->parse_template("member_uploadform");
BY:
if($action == "multiuploadform" || $action=="multiuploadimage")
{
$content = $site_template->parse_template("member_multiuploadform");
}
else
{
$content = $site_template->parse_template("member_uploadform");
}
FINALLY...
III. CREATE A PAGE FOR MULTIUPLOAD FORM 'member_multiuploadform.html'
- download the file from below and copy it to your template folder (of course rename to member_multiuploadform.html)
- you may un-comment more file items, if you expect the users to download smaller files. For me 5 is quite enough when uploading jpgs directly from 5MP digital camera... (I use the auto thumbnailer and auto resizer), but for photos from my 2MP camera I can use even 10...
- 4 images will just give (a bit misleading though), timeout error, if one tries to add too many images at once... complaining that you have invalid password(or something I can't recall...).
- Please edit this HTML to use your current locals (actually, you should add some variables to your language main.php -file...), I was too busy to do that.
...READY. Now starts the testing. :) (at first it is good to check that the 'normal' upload works as it used to... )
22 June 2005 CORRECTED the steps II.2 and II.7 were changed
23 June 2005 CORRECTED I fixed step II.2, incorrectly, leaving out the ".$fileext"-extension when checking the input files. And added a new II.2.2, to enable the auto thumbnailing...
26 July 2005 ADDED attachments of 'clean' multiupload files.
27 July 2005 UPDATED the instructions to match the provided files.