so it's just the start to do multiupload for user like the admin panel.
If somebody are interested to work with me at it, no prob
http://www.adcity.fr/4images/login :test
pasword :test
there is an exemple for the upload section, but it doesn't run for the moment
To do : (it's just suggestion

)
/////////////////////////////////////////////////////////////////////////////
- in admin section, part where you can define authorization for multi-upload (or wich user can)
- define correctly the aera for having input like : $image_name_$i or something like this
- optimized the following bad code
/////////////////////////////////////////////////////////////////////////////
so that the first part of my code :
Don't use the following code, doesn't workbut it may be a sart of mod?
in member.php
replace "
if ($action == "uploadimage") {..." and "
if ($action == "uploadform") {... "by
/////////////////////////////////////////////////////////////////////////////
if ($action == "uploadimage") {
if ($cat_id != 0 && (!isset($cat_cache[$cat_id]) || !check_permission("auth_upload", $cat_id))) {
show_error_page($lang['no_permission']);
exit;
}
$txt_clickstream = "";
if ($cat_id && isset($cat_cache[$cat_id])) {
$txt_clickstream .= get_category_path($cat_id, 1).$config['category_separator'];
}
$txt_clickstream .= $lang['user_upload'];
for ($i = 1; $i <= $num_newimages; $i++) {
$remote_media_file = format_url(un_htmlspecialchars(trim($HTTP_POST_VARS['remote_media_file_'.$i])));
$remote_thumb_file = format_url(un_htmlspecialchars(trim($HTTP_POST_VARS['remote_thumb_file_'.$i])));
$image_name = un_htmlspecialchars(trim($HTTP_POST_VARS['image_name_'.$i]));
$image_description = un_htmlspecialchars(trim($HTTP_POST_VARS['image_description_'.$i]));
$image_keywords = un_htmlspecialchars(trim($HTTP_POST_VARS['image_keywords_'.$i]));
$image_keywords = preg_replace("/[\n\r]/is", " ", $image_keywords);
$image_keywords = str_replace(","," ",$image_keywords);
$image_keywords = ereg_replace("( ){2,}", " ", $image_keywords);
$image_active = (isset($HTTP_POST_VARS['image_active_'.$i]) && $HTTP_POST_VARS['image_active_'.$i] == 0) ? 0 : 1;
$image_allow_comments = (isset($HTTP_POST_VARS['image_allow_comments_'.$i]) && $HTTP_POST_VARS['image_allow_comments_'.$i] == 0) ? 0 : 1;
$image_download_url = (isset($HTTP_POST_VARS['image_download_url_'.$i])) ? format_url(un_htmlspecialchars(trim($HTTP_POST_VARS['image_download_url_'.$i]))) : "";
$direct_upload = (check_permission("auth_directupload", $cat_id)) ? 1 : 0;
$upload_cat = ($direct_upload) ? $cat_id : 0;
}
$error = 0;
$uploaderror = 0;
if ($cat_id == 0) {
$error = 1;
$field_error = preg_replace("/".$site_template->start."field_name".$site_template->end."/siU", str_replace(":", "", "<span class='green'>".$lang['category']."</span>"), $lang['field_required']);
$msg .= (($msg != "") ? "<br />" : "")."$ico_green ".$field_error;
}
if ((empty($HTTP_POST_FILES['media_file'.$i]['tmp_name']) || $HTTP_POST_FILES['media_file'.$i]['tmp_name'] == "none") && ($remote_media_file == "" || !check_remote_media($remote_media_file))) {
$error = 1;
$msg .= (($msg != "") ? "<br />" : "")."$ico_green ".$lang['image_file_required'];
}
if ($image_name == "") {
$error = 1;
$field_error = preg_replace("/".$site_template->start."field_name".$site_template->end."/siU", str_replace(":", "","<span class='green'>". $lang['image_name']."</span>"), $lang['field_required']);
$msg .= (($msg != "") ? "<br />" : "")."$ico_green ".$field_error;
}
if (!empty($additional_image_fields)) {
foreach ($additional_image_fields as $key => $val) {
if (isset($HTTP_POST_VARS[$key]) && intval($val[2]) == 1 && trim($HTTP_POST_VARS[$key]) == "") {
$error = 1;
$field_error = preg_replace("/".$site_template->start."field_name".$site_template->end."/siU", str_replace(":", "", $val[0]), $lang['field_required']);
$msg .= (($msg != "") ? "<br />" : "").$field_error;
}
}
}
if (!$error) {
// Start Upload
include(ROOT_PATH.'includes/upload.php');
$site_upload = new Upload();
// Upload Media file
if (!empty($HTTP_POST_FILES['media_file'.$i]['tmp_name']) && $HTTP_POST_FILES['media_file'.$i]['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;
}
// Uplad thumb file
$new_thumb_name = "";
if (!empty($HTTP_POST_FILES['thumb_file']['tmp_name']) && $HTTP_POST_FILES['thumb_file']['tmp_name'] != "none" && !$uploaderror) {
$new_thumb_name = $site_upload->upload_file("thumb_file", "thumb", $upload_cat, basename($new_name));
if (!$new_thumb_name) {
$msg .= (($msg != "") ? "<br />" : "")."<b>".$lang['thumb_upload_error'].": ".$new_thumb_name."</b><br />".$site_upload->get_upload_errors();
@unlink(MEDIA_TEMP_PATH."/".$new_name);
$uploaderror = 1;
}
}
elseif (check_remote_thumb($remote_thumb_file)) {
$new_thumb_name = $remote_thumb_file;
}
elseif ($config['auto_thumbnail'] == 1 && !empty($HTTP_POST_FILES['media_file']['tmp_name']) && $HTTP_POST_FILES['media_file']['tmp_name'] != "none" && !$uploaderror) {
if ($direct_upload) {
$src = MEDIA_PATH."/".$cat_id."/".$new_name;
$dest = THUMB_PATH."/".$cat_id."/".$new_name;
}
else {
$src = MEDIA_TEMP_PATH."/".$new_name;
$dest = THUMB_TEMP_PATH."/".$new_name;
}
$do_create = 0;
if ($image_info = @getimagesize($src)) {
if ($image_info[2] == 1 || $image_info[2] == 2 || $image_info[2] == 3) {
$do_create = 1;
}
}
if ($do_create) {
require(ROOT_PATH.'includes/image_utils.php');
$convert_options = init_convert_options();
if (!$convert_options['convert_error']) {
$dimension = (intval($config['auto_thumbnail_dimension'])) ? intval($config['auto_thumbnail_dimension']) : 100;
$resize_type = (intval($config['auto_thumbnail_resize_type'])) ? intval($config['auto_thumbnail_resize_type']) : 1;
$quality = (intval($config['auto_thumbnail_quality']) && intval($config['auto_thumbnail_quality']) <= 100) ? intval($config['auto_thumbnail_quality']) : 100;
if (create_thumbnail($src, $dest, $quality, $dimension, $resize_type)) {
$new_thumb_name = $new_name;
}
}
}
}
if (!$uploaderror) {
$additional_field_sql = "";
$additional_value_sql = "";
if (!empty($additional_image_fields)) {
$table = ($direct_upload) ? IMAGES_TABLE : IMAGES_TEMP_TABLE;
$table_fields = $site_db->get_table_fields($table);
foreach ($additional_image_fields as $key => $val) {
if (isset($HTTP_POST_VARS[$key]) && isset($table_fields[$key])) {
$additional_field_sql .= ", $key";
$additional_value_sql .= ", '".un_htmlspecialchars(trim($HTTP_POST_VARS[$key]))."'";
}
}
}
$current_time = time();
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.")";
$result = $site_db->query($sql);
$image_id = $site_db->get_insert_id();
if ($result) {
include(ROOT_PATH.'includes/search_utils.php');
$search_words = array();
foreach ($search_match_fields as $image_column => $match_column) {
if (isset($HTTP_POST_VARS[$image_column])) {
$search_words[$image_column] = stripslashes($HTTP_POST_VARS[$image_column]);
}
}
add_searchwords($image_id, $search_words);
}
}
else {
$sql = "INSERT INTO ".IMAGES_TEMP_TABLE."
(cat_id, user_id, image_name, image_description, image_keywords, image_date, image_media_file, image_thumb_file, image_download_url".$additional_field_sql.")
VALUES
($cat_id, ".$user_info['user_id'].", '$image_name', '$image_description', '$image_keywords', $current_time, '$new_name', '$new_thumb_name', '$image_download_url'".$additional_value_sql.")";
$result = $site_db->query($sql);
}
if ($config['upload_notify'] == 1 && !$direct_upload) {
include(ROOT_PATH.'includes/email.php');
$site_email = new Email();
$config['upload_emails'] = str_replace(" ", "", $config['upload_emails']);
$emails = explode(",", $config['upload_emails']);
$validation_url = $script_url."/admin/index.php?goto=".urlencode("validateimages.php?action=validateimages");
$site_email->set_to($config['site_email']);
$site_email->set_subject($lang['new_upload_emailsubject']);
$site_email->register_vars(array(
"image_name" => stripslashes($image_name),
"file_name" => $new_name,
"cat_name" => $cat_cache[$cat_id]['cat_name'],
"validation_url" => $validation_url,
"site_name" => $config['site_name']
));
$site_email->set_body("upload_notify", $config['language_dir_default']);
$site_email->set_bcc($emails);
$site_email->send_email();
}
$msg .= $lang['image_add_success'].": <b>".stripslashes($image_name)."</b> (".$new_name.")";
$msg .= (!$direct_upload) ? "<br />".$lang['new_upload_validate_desc'] : "";
$file_extension = get_file_extension($new_name);
$file = (is_remote($new_name)) ? $new_name : (($direct_upload) ? MEDIA_PATH."/".$cat_id."/".$new_name : MEDIA_TEMP_PATH."/".$new_name);
$width_height = "";
if (!is_remote($file) && $imageinfo = @getimagesize($file)) {
$width_height = " ".$imageinfo[3];
}
$media_icon = "<img src=\"".ICON_PATH."/".$file_extension.".gif\" border=\"0\" alt=\"\" />";
$site_template->register_vars(array(
"media_src" => $file,
"media_icon" => $media_icon,
"image_name" => stripslashes($image_name),
"width_height" => $width_height
));
$media = $site_template->parse_template("media/".$file_extension);
$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") {
if ($cat_id != 0 && (!isset($cat_cache[$cat_id]) || !check_permission("auth_upload", $cat_id))) {
show_error_page($lang['no_permission']);
exit;
}
if ($user_info['user_level'] == GUEST || $user_info['user_level'] == USER_AWAITING) {
show_error_page($lang['commander_register']);
}
$txt_clickstream = "";
if ($cat_id && isset($cat_cache[$cat_id])) {
$txt_clickstream .= get_category_path($cat_id, 1).$config['category_separator'];
}
$txt_clickstream .= $lang['user_upload'];
$nbr_pics="$nbr_pics";
for ($i = 1; $i <= $nbr_pics; $i++) {
$printform .="<table width=\"100%\" border=\"0\" cellspacing=\"0\" cellpadding=\"0\"><tr><td><strong>pics nbr : <span class='new'>$i</span></strong></td><td width=\"50%\"><div align=\"right\"><a href=\"#\">go_top</a></div></td></tr></table><br><br> <table width=\"100%\" border=\"0\" cellspacing=\"0\" cellpadding=\"0\"><tr><td ><table width=\"100%\" border=\"0\" cellspacing=\"0\" cellpadding=\"2\"><tr><td width=\"94%\"><input type=\"hidden\" name=\"action\" value=\"uploadimage\" /><input type=\"hidden\" name=\"cat_id\" value=\"{cat_id}\" /><table width=\"100%\" border=\"0\" cellspacing=\"0\" cellpadding=\"1\"><tr><td valign=\"top\" class=\"row2\"><table width=\"100%\" border=\"0\" cellpadding=\"4\" cellspacing=\"0\"><tr><td ><b>{lang_category}</b></td><td >".get_category_dropdown($cat_id)."</td></tr><tr><td valign=\"top\"><b>{lang_media_file}</b><br /><span class=\"smalltext\">{lang_max_filesize}<b>{max_media_filsize}</b><br />{lang_max_imagewidth}<b>{max_media_imagewidth}</b><br />{lang_max_imageheight}<b>{max_media_imageheight}</b><br /></span></td><td ><b>Upload:</b><br /><input type=\"file\" name=\"media_file_".$i."\" class=\"input\" /><br /><b>URL:</b><br /><input type=\"text\" name=\"remote_media_file_".$i."\" size=\"30\" value=\"$remote_file\" class=\"input\" /><br /><span class=\"smalltext\"><b>{lang_allowed_file_types}</b>{allowed_media_types}</span></td></tr><tr><td valign=\"top\"><b>{lang_thumb_file}</b><br /><span class=\"smalltext\">{lang_max_filesize}<b>{max_thumb_filsize}</b><br />{lang_max_imagewidth}<b>{max_thumb_imagewidth}</b><br />{lang_max_imageheight}<b>{max_thumb_imageheight}</b><br /></span></td><td ><b>Upload:</b><br /><input type=\"file\" name=\"thumb_file_".$i."\" class=\"input\" /><br /><b>URL:</b><br /><input type=\"text\" name=\"remote_thumb_file_".$i."\" size=\"30\" value=\"{remote_thumb_file}\" class=\"input\" /><br /><span class=\"smalltext\"><b>{lang_allowed_file_types}</b>{allowed_thumb_types}</span></td></tr><tr><td ><b>{lang_image_name}</b></td><td ><input type=\"text\" name=\"image_name_".$i."\" size=\"30\" value=\"{image_name}\" class=\"input\" /></td></tr><tr><td valign=\"top\"><b>{lang_description}</b></td><td ><textarea name=\"image_description_".$i."\" cols=\"30\" class=\"textarea\" rows=\"10\" wrap=\"VIRTUAL\">{image_description}</textarea></td></tr><tr><td valign=\"top\"><b>{lang_keywords}</b></td> <td ><textarea cols=\"30\" class=\"textarea\" rows=\"10\" wrap=\"VIRTUAL\" name=\"image_keywords_".$i."\">{image_keywords}</textarea></td></tr></table></td></tr></table></td><td width=\"3%\"> </td></tr></table></td></tr></table>";
}
if (!$sendprocess) {
$remote_media_file = "";
$remote_thumb_file = "";
$image_name = "";
$image_description = "";
$image_keywords = "";
$image_download_url = "";
$image_allow_comments = 1;
}
$site_template->register_vars(array(
"printform" => $printform,
"cat_id" => $cat_id,
"cat_name" => ($cat_id != 0) ? htmlspecialchars($cat_cache[$cat_id]['cat_name']) : get_category_dropdown($cat_id),
"remote_media_file" => htmlspecialchars(stripslashes($remote_media_file)),
"remote_thumb_file" => htmlspecialchars(stripslashes($remote_thumb_file)),
"image_name" => htmlspecialchars(stripslashes($image_name)),
"image_description" => htmlspecialchars(stripslashes($image_description)),
"image_keywords" => htmlspecialchars(stripslashes($image_keywords)),
"image_allow_comments_yes" => ($image_allow_comments) ? " checked=\"checked\"" : "",
"image_allow_comments_no" => (!$image_allow_comments) ? " checked=\"checked\"" : "",
"image_download_url" => htmlspecialchars(stripslashes($image_download_url)),
"lang_category" => $lang['category'],
"lang_user_upload" => $lang['user_upload'],
"lang_media_file" => $lang['media_file'],
"lang_thumb_file" => $lang['thumb_file'],
"lang_allowed_file_types" => $lang['allowed_mediatypes_desc'],
"allowed_media_types" => str_replace(",",", ",$config['allowed_mediatypes']),
"allowed_thumb_types" => "jpg, gif, png",
"lang_max_filesize" => $lang['max_filesize'],
"lang_max_imagewidth" => $lang['max_imagewidth'],
"lang_max_imageheight" => $lang['max_imageheight'],
"max_thumb_filsize" => $config['max_thumb_size']." ".$lang['kb'],
"max_thumb_imagewidth" => $config['max_thumb_width']." ".$lang['px'],
"max_thumb_imageheight" => $config['max_thumb_height']." ".$lang['px'],
"max_media_filsize" => $config['max_media_size']." ".$lang['kb'],
"max_media_imagewidth" => $config['max_image_width']." ".$lang['px'],
"max_media_imageheight" => $config['max_image_height']." ".$lang['px'],
"lang_image_name" => $lang['image_name'],
"lang_description" => $lang['description'],
"lang_keywords" => $lang['keywords_ext'],
"lang_allow_comments" => isset($lang['allow_comments']) ? $lang['allow_comments'] : "",
"lang_submit" => $lang['submit'],
"lang_reset" => $lang['reset'],
"lang_yes" => $lang['yes'],
"lang_no" => $lang['no'],
"lang_nbr_pics" => $lang['nbr_pics'],
"nbr_pics" => $nbr_pics,
"lang_cut" => $lang['cut'],
"lang_image" => $lang['image'],
"lang_right_type" => $lang['right_type'],
"lang_right_type1" => $lang['right_type1'],
"lang_right_type2" => $lang['right_type2'],
"lang_right_type3" => $lang['right_type3']
));
if (!empty($additional_image_fields)) {
$additional_field_array = array();
foreach ($additional_image_fields as $key => $val) {
if ($val[1] == "radio") {
$value = (isset($HTTP_POST_VARS[$key])) ? intval($HTTP_POST_VARS[$key]) : 1;
if ($value == 1) {
$additional_field_array[$key.'_yes'] = " checked=\"checked\"";
$additional_field_array[$key.'_no'] = "";
}
else {
$additional_field_array[$key.'_yes'] = "";
$additional_field_array[$key.'_no'] = " checked=\"checked\"";
}
}
else {
$value = (isset($HTTP_POST_VARS[$key])) ? htmlspecialchars(stripslashes(trim($HTTP_POST_VARS[$key]))) : "";
}
$additional_field_array[$key] = $value;
$additional_field_array['lang_'.$key] = $val[0];
}
if (!empty($additional_field_array)) {
$site_template->register_vars($additional_field_array);
}
}
$content = $site_template->parse_template("member_uploadform");
}
Replace all the code in
template/{your template folder}/member_uploadform.html
by
///////////////////////////////////////////////////////////////////////////////
<table width="100%" border="0" cellspacing="0" cellpadding="0" >
<tr>
<td>{lang_user_upload} <div align="right"></div></td>
</tr>
<tr>
<td> <hr size="1" color="#2C2C2C"></td>
</tr>
</table>
<br>
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<form name="form1" method="post" action="{url_upload}">
<td width="50%"><div align="right"> {lang_nbr_pics}
<select name="nbr_pics">
<option value="1" selected>1</option>
<option value="2">2</option>
<option value="3">3</option>
<option value="4">4</option>
<option value="5">5</option>
</select>
<input type="submit" name="uploadbutton" value="ok" class="button" />
</div></td>
</form>
</tr>
</table>
<br><form method="post" action="{url_member}" enctype="multipart/form-data" onsubmit="uploadbutton.disabled=true;">
<div align="center">{printform} </div>
<p align="center">
<input type="submit" name="uploadbutton" value="{lang_submit}" class="button" />
<input type="reset" value="{lang_reset}" class="button" />
</p>
</form>
that all for the moment.