Jonathan Wagener wrote:
Hi, i am trying to add a function my gallery app that i builkt in php/mysql to
allow people to upload a zip file of JPG images and the system would extract
the JPGs, rename them, reference them in MySQL, create thumbnails, and then
move the images to their directories.
I have seen this function in all the galleries that i have looked at and have
googled the problem but i have not found a good answer. I have been struggling
with this issue for two days now.
Jonathan Wagener
Hi!
I added this to my piviviewer app (Picture & Video Viewer) and it works great.
I call the feature 'turboload' as I managed to jam 800 jpegs straight from my
camera into my system within a matter of minutes. I store the images with a
dummy name so that I can later query for it and add the description and search
tags whenever I like. I attached the two scripts that show the upload form
allowing for both direct upload or using the cURL library to obtain the file
from somewhere else (for example the FTP server that is on the web server, so
one can first upload via FTP and then load from the same box, which makes
things much quicker within the app). The zip library is then used to unzip the
files and add them to the system. I also use exif to read out the date stamp
as I let my system arrange the uploaded images in a directory structure that
is based on year and month. That way I have at least some structure that I can
outside of the app.
In case you wonder, I made my app to be language aware so that some of the
queries go to language dependent tables. The current user language and some of
the basic file paths are stored in $_SESSION, so you will find several
references to $_SESSION. You can just ignore all that stuff and pick out what
you need. My scripts are extensively commented, which helps me a lot. I first
write the comment for the next step to take and then write the code for it.
Oh, and 80% of these scripts are from NYPHP anyway, so if you find it useful,
thank the good helpers on this list. The remaining 20% are the comments, hehe.
David
<?php
// ****************************************************************************
// This script provides a file browse box for uploading a ZIP archive that
// contains images to be added via turboloader. PHP INI settings are set to
// allow for larger file uploads.
// Text box allows for specifying HTTP/FTP URLs for alreadz uploaded files.
// ****************************************************************************
// Start / continue session
session_start();
// Allow for 50 MB max uploads
// Assumptions: server is set to allow for large uploads, uploads are done in
// 10 minutes - set php.ini to allow for large uploads
ini_set('max_execution_time', '600');
// Require header
require('..\..\include\header.php');
// Show title
showtitle("Upload picture ZIP package for TurboLoader");
echo "<p class=\"center\" >Select the ZIP file or specify a URL (HTTP/FTP) from
where to load the package.<br />\n";
echo "FTP URLs have to be in format ftp://username:[EMAIL
PROTECTED]/pics.zip.</p>\n";
// Start form
echo "<form method=\"post\" action=\"tlsubmit.php\" ".
" enctype=\"multipart/form-data\" >\n";
// Show browse box
echo "<p class=\"indentten\" ><input type=\"radio\" name=\"uploadtype\"
value=\"zip\" checked=\"checked\">".
" File upload <input type=\"file\"
name=\"zipupload\" />".
"</p>\n";
// Show URL text box
echo "<p class=\"indentten\" ><input type=\"radio\" name=\"uploadtype\"
value=\"url\"> URL upload".
" <input type=\"text\" name=\"urlupload\" size=\"100\"/>".
"</p>\n";
// Show drop-down for User Level
echo "<p class=\"indentten\">View Level for all pictures: ".
"<select name=\"level\">\n".
"<option value=\"4\" selected=\"selected\">SuperAdmin</option>\n".
"<option value=\"3\">Admin</option>\n".
"<option value=\"2\">User</option>\n".
"<option value=\"1\">Guest</option>\n".
"</select>\n".
"</p>";
// Show radio buttons for stats
echo "<p class=\"indentten\" >Show processing statistics?</p>\n".
"<p class=\"indentten\" ><input type=\"checkbox\" name=\"genstats\"
value=\"1\" checked=\"checked\">".
" Show general statistics</p>\n".
"<p class=\"indentten\" ><input type=\"checkbox\" name=\"dbstats\"
value=\"1\" checked=\"checked\">".
" Show database statistics</p>\n".
"<p class=\"indentten\" ><input type=\"checkbox\" name=\"filestats\"
value=\"1\" checked=\"checked\">".
" Show file statistics</p>\n";
// Show buttons
echo "<p class=\"center\" >";
echo "<input type=\"submit\" value=\"Submit\" /> ".
"<input type=\"reset\" value=\"Reset\" />\n</p>\n";
// Close form
echo "</form>\n";
?>
</body>
</html>
<?php
// ****************************************************************************
// This script gets either a larger ZIP archive sent directly or an FTP/HTTP
// URL from which the file is to be downloaded. Make decision as to where file
// is coming from, retrieve and secure file, check if file is valid ZIP archive,
// if yes, unpack, loop through all files, check each file for valid format,
// obtain exif info, stuff file into database with default values.
// Note: All statistics get buffered into strings except for initial error
// messages and cURKL stats, which will always be shown.
// ****************************************************************************
// Start / continue session
session_start();
// Allow for 10 minutes maximum execution time due to file download
ini_set('max_execution_time', '600');
// ############################################################################
// FUNCTIONS
// ############################################################################
// FUNCTION errmessage
// ############################################################################
function errmessage ($fct_msgstring = "OUCH! File upload error!") {
// Show title
showtitle("Uploading ZIP package failed");
// Start form
echo "<form method=\"post\" action=\"turboloadpics.php\" >\n";
// Show error message
echo "<p class=\"center\" >".$fct_msgstring."</p>\n<br />\n";
// Show button
echo "<p class=\"center\" > ";
echo "<input type=\"submit\" value=\"Return to file upload\" />\n";
echo "</p>\n";
// End form
echo "</form>\n";
// End page
echo "</body>\n";
echo "</html>\n";
// End script
exit;
}
// ############################################################################
// FUNCTION rmdirtree (from http://www.php.net/rmdir)
// ############################################################################
function rmdirtree($dirname) {
if (is_dir($dirname)) { //Operate on dirs only
$result=array();
if (substr($dirname,-1)!='/') {$dirname.='/';} //Append slash if
necessary
$handle = opendir($dirname);
while (false !== ($file = readdir($handle))) {
if ($file!='.' && $file!= '..') { //Ignore . and ..
$path = $dirname.$file;
if (is_dir($path)) { //Recurse if subdir, Delete if file
$result=array_merge($result,rmdirtree($path));
}else{
unlink($path);
$result[].=$path;
}
}
}
closedir($handle);
rmdir($dirname); //Remove dir
$result[].=$dirname;
return $result; //Return array of deleted items
}else{
return false; //Return false if attempting to operate on a file
}
}
// ############################################################################
// ----------------------------------------------------------------------------
// Initialize variables
// ----------------------------------------------------------------------------
// From $_SESSION
$root= "";
// From $_FILES
$zipupload = array();
// From $_POST
$uploadtype = "";
$urlupload = "";
$level = 0;
$genstats = 0;
$dbstats = 0;
$filestats = 0;
// For script
$nourl = FALSE;
$sessionid = "";
$sessiondir = "";
$localzipfile = "";
$zipfile = "";
$resource = "";
$zipupload = "";
$output = "";
$curlsession = "";
$curlerror = "";
$curlstatus = "";
$curlerrornumber = "";
$zipcounter = 0;
$zipentry = "";
$counter = 0;
$filearray = array();
$addcounter = 0;
$fileinfo = array();
$now = array();
$year = "";
$month = "";
$day = "";
$hour = "";
$minute = "";
$second = "";
$tempfilename = "";
$filename = "";
$fileinfo = array();
$splitdate = array();
$splittime = array();
$splitdatetime = array();
$fileoriginaldate = array();
$finaldiryear = "";
$finaldirmonth = "";
$moveok = 0;
$makedirok = 0;
$langcounter = 0;
$langquery = "";
$langqueryrun = "";
$langqueryresult = "";
$langarray = array();
$finallocation = "";
$tableinsertresult = "";
$entitydate = "";
$now = "";
$entityid = 0;
$namecounter = 0;
$nametable = "";
$namequery = "";
$pivientitiesquery = "";
$pivientitiesqueryrun = "";
$pivinamequery = "";
$pivinamequeryrun = "";
$pivilocationquery = "";
$pivilocationqueryrun = "";
$genstring = "";
$dbstring = "Insert into ";
$filestring = "";
$starttime = 0;
$endtime = 0;
$fileerror = 0;
$dberror = 0;
$filesworked = 0;
// ----------------------------------------------------------------------------
// Get start time
$starttime = microtime(true);
// Get values from $_POST
if (isset($_POST['uploadtype'])) $uploadtype = $_POST['uploadtype'];
if (isset($_POST['urlupload'])) $urlupload = $_POST['urlupload'];
if (isset($_POST['level'])) {
$level = $_POST['level'];
} else {
$level = 4;
}
if (isset($_POST['genstats'])) $genstats = $_POST['genstats'];
if (isset($_POST['dbstats'])) $dbstats = $_POST['dbstats'];
if (isset($_POST['filestats'])) $filestats = $_POST['filestats'];
// Get values from $_SESSION
if (isset($_SESSION['sessionfilepathtoroot'])) $root =
$_SESSION['sessionfilepathtoroot'];
// Prepare for output - Require header
require('..\..\include\header.php');
// Make session dir if it doesn't exist already
// Get session id
$sessionid = session_id();
// Make dir name
$sessiondir = ".".DIRECTORY_SEPARATOR.$sessionid;
// Create folder unless it exists already
if (!is_dir($sessiondir)) {
// dir does not exist, create it
mkdir($sessionid);
}
// Check for upload type to be present
if ($uploadtype == "") errmessage("OUCH! - Upload type missing!");
// Determine what to do
if ($uploadtype == "zip") {
// Get array from $_FILES
$zipupload = $_FILES['zipupload'];
// Copy file to temp folder
if (!copy($zipupload['tmp_name'],
$sessiondir.DIRECTORY_SEPARATOR.$zipupload['name'])) {
errmessage("OUCH - Copying the file ".$zipupload['name'].
" to temporary storage failed! Try again!");
} else {
//Copying worked, so dump temporary file
unlink($zipupload['tmp_name']);
// Show title
showtitle("Uploading ZIP package was successful");
}
}
if ($uploadtype == "url") {
// Check if URL text was submitted and has a reasonable chance to work
if ($urlupload == "") $nourl = TRUE;
if ($nourl == FALSE) {
if (substr($urlupload, 0, 7) != "http://") {
if(substr($urlupload, 0, 6) != "ftp://") {
$nourl = FALSE;
}
}
}
// Attempt to obtain file
if ($nourl == FALSE) {
// Make local zip file path and name
$localzipfile = $sessiondir.DIRECTORY_SEPARATOR.$sessionid.".zip";
// Get file using cURL
// Open output file
$output = fopen($localzipfile, 'wb');
// Check if opening file worked
if ($output == FALSE){
errmessage("OUCH! Could not open local file for download!");
}
// Take care of spaces in url
$urlupload = str_replace(" ", "%20", $urlupload);
// Start cURL session
$curlsession = curl_init();
// Set cURL options for download
curl_setopt($curlsession, CURLOPT_FILE, $output);
curl_setopt($curlsession, CURLOPT_HEADER, 0);
curl_setopt($curlsession, CURLOPT_BINARYTRANSFER, 1);
curl_setopt($curlsession, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($curlsession, CURLOPT_URL, $urlupload);
// Execute cURL sessions
$curlstatus = curl_exec($curlsession);
// Check for errors
if($curlstatus == FALSE) {
$curlerror = curl_error($curlsession);
$curlerrornumber = curl_errno($curlsession);
// Close cURL session
curl_close($curlsession);
// Close output file
fclose($output);
// Show error message
errmessage("Download failed! Error: ".
$curlerror.", Error Number: ".$curlerrornumber);
} else {
// Get some cURL stats
$curlinfo = curl_getinfo($curlsession);
// Load HTTP codes
$http_codes =
parse_ini_file(".".DIRECTORY_SEPARATOR."http_codes.ini");
// Show title
showtitle("Uploading ZIP package was successful");
// Show sub title
echo "<p class=\"centerbold\">Transfer Statistics</p>\n";
// Start output
echo "<p class=\"indentcloser\">";
// Echo url
echo "Last effective URL: ".$curlinfo['url']."<br />\n";
// Echo content_type
echo "Content-type of downloaded object:
".$curlinfo['content_type']."<br />\n";
// Echo http_code
echo "Last received HTTP code: ".$curlinfo['http_code'].
" ".$http_codes[$curlinfo['http_code']]."<br />\n";
// Echo header_size
echo "Total size of all headers received:
".$curlinfo['header_size']."<br />\n";
// Echo request_size
echo "Total size of issued requests:
".$curlinfo['request_size']."<br />\n";
// Echo filetime
echo "Remote time of the retrieved document:
".$curlinfo['filetime']."<br />\n";
// Do not echo ssl_verify_result
// echo "Result of SSL certification verification requested:
".$curlinfo['ssl_verify_result']."<br />\n";
// Echo redirect_count
echo "Number of redirects: ".$curlinfo['redirect_count']."<br
/>\n";
// Echo total_time
echo "Total transaction time in seconds for last transfer: "
.$curlinfo['total_time']." s<br />\n";
// Echo namelookup_time
echo "Time in seconds until name resolving was complete: "
.$curlinfo['namelookup_time']." s<br />\n";
// Echo connect_time
echo "Time in seconds it took to establish the connection: "
.$curlinfo['connect_time']." s<br />\n";
// Echo pretransfer_time
echo "Time in seconds from start until just before file
transfer begins: "
.$curlinfo['pretransfer_time']." s<br />\n";
// Echo size_upload
echo "Total number of bytes uploaded: "
.$curlinfo['size_upload']." Bytes<br />\n";
// Echo size_download
echo "Total number of bytes downloaded: "
.$curlinfo['size_download']." Bytes<br />\n";
// Echo speed_download
echo "Average download speed: "
.$curlinfo['speed_download']." Bytes/s<br />\n";
// Echo speed_upload
echo "Average upload speed: "
.$curlinfo['speed_upload']." Bytes/s<br />\n";
// Echo download_content_length
echo "Content-length of download:
".$curlinfo['download_content_length']." Bytes<br />\n";
// Echo upload_content_length
echo "Content-length of upload:
".$curlinfo['upload_content_length']." Bytes<br />\n";
// Echo starttransfer_time
echo "Time in seconds until the first byte is about to be
transferred: "
.$curlinfo['starttransfer_time']." s<br />\n";
// Echo redirect_time
echo "Time in seconds of all redirection steps before final
transaction was started: "
.$curlinfo['redirect_time']." s<br />\n";
// Close output for now
echo "</p>\n";
}
// Close cURL session
curl_close($curlsession);
// Close output file
fclose($output);
}
// Check if error occured
if($nourl == TRUE) {
errmessage("OUCH - Downloading the file from ".$urlupload.
" to temporary storage failed! Try again!");
}
}
// File is in session dir, set one variable to be the lone file name
if ($uploadtype == "zip") $localzipfile = $root.DIRECTORY_SEPARATOR.
"administration".DIRECTORY_SEPARATOR.
"pics".DIRECTORY_SEPARATOR.
$sessionid.DIRECTORY_SEPARATOR.$zipupload['name'];
if ($uploadtype == "url") $localzipfile = $root.DIRECTORY_SEPARATOR.
"administration".DIRECTORY_SEPARATOR.
"pics".DIRECTORY_SEPARATOR.
$sessionid.DIRECTORY_SEPARATOR.$sessionid.".zip";
// Check if local file is indeed a valid ZIP file, if yes, unzip
$zipfile = new ZipArchive;
$resource = $zipfile->open($localzipfile);
if ($resource === TRUE) {
$zipfile->extractTo($sessiondir.DIRECTORY_SEPARATOR);
$zipfile->close();
} else {
errmessage("OUCH! Opening ZIP file failed. Error code: ".$resource);
}
// Create file and folder array from ZIP archive
// Open ZIP archive
$zip = zip_open($localzipfile);
if ($zip) {
while ($zip_entry = zip_read($zip)) {
// When it is a file (file size not 0) add to array
if (zip_entry_filesize($zip_entry) > 0) {
$filearray[$counter] = $root.DIRECTORY_SEPARATOR.
"administration".DIRECTORY_SEPARATOR.
"pics".DIRECTORY_SEPARATOR.
$sessionid.DIRECTORY_SEPARATOR.
zip_entry_name($zip_entry);
$counter++;
}
}
// Close ZIP file
zip_close($zip);
}
// Dump ZIP file, no longer needed
unlink($localzipfile);
// Link to database
require('..\..\include\connect2db.php');
// Get info about all language specific tables
// Create query
$langquery = "SELECT Languages FROM pivisettings";
// Run query
$langqueryrun = mysql_query ($langquery, $pivilink);
// Get result, there can be only one line
$langqueryresult = mysql_fetch_assoc($langqueryrun);
// Turn language column string into array
$langresult = explode(";", $langqueryresult['Languages']);
// Build nice array
while ($langcounter != count($langresult)) {
// Make final array components
$langarray[$langcounter] = $langresult[$langcounter];
$langcounter++;
$langcounter++; // Have to increas counter by 2 as two elements were used
}
// Rekey language array, makes looping easier later
$langarray = array_values($langarray);
// Loop through $filearray and add each picture to system
while ($addcounter < $counter) {
// Get file name from array
$tempfilename = $filearray[$addcounter];
// Get file name only
$filename = basename($tempfilename);
// IMPORTANT: Reset flag for $moveok and $makedirok
$moveok = 0;
$makedirok = 0;
// Use exif to get original date from file, works only with jpg and tif
$fileinfo = exif_read_data($tempfilename);
// Can always get all other info later
if (!isset($fileinfo['DateTimeOriginal'])) {
// Reading exif data failed, so set some defaults
// Get time
$now = localtime(time(), true);
// Make year
$year = $now['tm_year']+1900;
// Make month
if ($now['tm_mon'] < 9) {
$month = $now['tm_mon'];
$month = "0".$now['tm_mon'];
} else {
$month = $now['tm_mon'];
}
// Make day
if ($now['tm_mday'] < 9) {
$day = "0".$now['tm_mday'];
} else {
$day = $now['tm_mday'];
}
// Make hour
if ($now['tm_hour'] < 9) {
$hour = "0".$now['tm_hour'];
} else {
$hour = $now['tm_hour'];
}
// Make minute
if ($now['tm_min'] < 9) {
$minute = "0".$now['tm_min'];
} else {
$minute = $now['tm_min'];
}
// Make second
if ($now['tm_sec'] < 9) {
$second = "0".$now['tm_sec'];
} else {
$second = $now['tm_sec'];
}
// Set size default
$size = "";
} else {
$fileoriginaldate = $fileinfo['DateTimeOriginal'];
// Split into year:month:day and hour:minute:second
$splitdatetime = explode(" ", $fileoriginaldate);
$splitdate = explode(":", $splitdatetime['0']);
$splittime = explode(":", $splitdatetime['1']);
$year = $splitdate['0'];
$month = $splitdate['1'];
$day = $splitdate['2'];
$hour = $splittime['0'];
$minute = $splittime['1'];
$second = $splittime['2'];
}
// Move file from temporary storage to final location
// Pad date and time submissions except year with 0, if too short
$month = str_pad ($month, 2, "0", STR_PAD_LEFT);
$day = str_pad ($day, 2, "0", STR_PAD_LEFT);
$hour = str_pad ($hour, 2, "0", STR_PAD_LEFT);
$minute = str_pad ($minute, 2, "0", STR_PAD_LEFT);
$second = str_pad ($second, 2, "0", STR_PAD_LEFT);
// Find out if target directory exists, if not create it and move file,
// if not, create directory, then move file
$finaldiryear =
$_SESSION['sessionfilepathtoroot'].DIRECTORY_SEPARATOR."entities".
DIRECTORY_SEPARATOR.$year;
$finaldirmonth =
$_SESSION['sessionfilepathtoroot'].DIRECTORY_SEPARATOR."entities".
DIRECTORY_SEPARATOR.$year.DIRECTORY_SEPARATOR.$month;
// Check if target file was submitted previously
if (file_exists($finaldirmonth.DIRECTORY_SEPARATOR.$filename)) {
// No need to add file
$filestring = $filestring."<p class=\"indentten\" >File ".$filename.
" already exists in system! The file was not added. <br
/></p>\n";
// Increase $fileerror
$fileerror++;
// Do file cleanup, whack temp file
unlink($tempfilename);
// Drop out of loop and start over for next picture in array
// Have to increase counter. I just hope this works!
$addcounter++;
continue;
}
// Now move file to final location
if (is_dir($finaldirmonth)) {
// Directory exists, copy temp file, delete temp file on copy
success
if (rename ($tempfilename,
$finaldirmonth.DIRECTORY_SEPARATOR.$filename)) {
$moveok = 1; // Moving worked
} else {
$filestring = $filestring."<p class=\"indentten\" >Moving
file ".$filename.
" to final location failed!<br /></p>\n";
// Do file cleanup, whack temp file
unlink($tempfilename);
// Drop out of loop and start over for next picture in array
// Have to increase counter. I just hope this works!
$addcounter++;
continue;
}
} else {
// Directory does not exist, create it, copy temp file, delete temp
file
// on copy success
if (!is_dir($finaldiryear)) {
mkdir($finaldiryear);
}
if (!is_dir($finaldirmonth)) {
mkdir($finaldirmonth);
}
if (is_dir($finaldirmonth)) {
$makedirok = 1;
} else {
$makedirok = 0;
}
if ($makedirok == 1) {
// Move only when directory was created successfully
if (rename ($tempfilename,
$finaldirmonth.DIRECTORY_SEPARATOR.$filename)) {
$moveok = 1; // Moving worked
} else {
$filestring = $filestring."<p class=\"indentten\"
>Creating folder and moving file ".$filename.
" to final location failed!<br /></p>\n";
// Do file cleanup, whack temp file
unlink($tempfilename);
// Drop out of loop and start over for next picture in
array
// Have to increase counter.
$addcounter++;
continue;
}
}
}
// Check if file is really there and show message, didn't work for some
reason in
// if clause further up where file was moved using rename. No clue why it
fails there.
if (is_file($finaldirmonth.DIRECTORY_SEPARATOR.$filename)) {
$filestring = $filestring."<p class=\"indentten\">Insert results:
Moving file ".$filename.
" to final location worked!</p>\n";
}
// ======================================================================
// ======================================================================
// ======================================================================
// FILE IS IN FINAL LOCATION - ADD ENTRIES TO DATABASE TABLES
// ======================================================================
// ======================================================================
// ======================================================================
// PUH! File is where it belongs and is ready to get record in database.
// If there was any error the loop would not get to this point.
// Following information is available for insert into database
// Name: "~~~~~"
// Location: "~~~~~"
// Date and Time: $year $month $day $hour $minute $second
// Final location: $finallocation
// Prep dbstring
$dbstring = $dbstring."<p class= \"indentten\"> ".$filename.": ";
// Make $finallocation
$finallocation = $year."\\".$month."\\".$filename;
// Escape $finallocation
$finallocation = mysql_real_escape_string($finallocation);
// ----------------------------------------------------------------------
// PIVIENTITIES
// ----------------------------------------------------------------------
// Make date string
$entitydate = $year."-".$month."-".$day." ".$hour.":".$minute.":".$second;
// Make now timestamp
$now = date('Y-m-d H:i:s');
// Make query for pivientities
$pivientitiesquery = "INSERT INTO pivientities ".
"(Entitytype, Creation_date, Filepath, Views, ".
"Last_viewed, Who_last_viewed, Added, Level, Rotate)
".
"VALUES (".
"'pic', '".$entitydate."', '".$finallocation."',
'1', ".
"'".$now."', '".$_SESSION['sessionaccountid']."',
'".$now."', ".
"'".$level."', '0')";
// Run query
$pivientitiesqueryrun = mysql_query($pivientitiesquery);
// Check for success
if ($pivientitiesqueryrun == FALSE) {
$dbstring = $dbstring."pivientities=FAILED, ";
$dberror++;
} else {
$dbstring = $dbstring."pivientities=WORKED, ";
}
// ----------------------------------------------------------------------
// Get ID of last insert hoping that it is the insert that we made
$entityid = mysql_insert_id($pivilink);
// ----------------------------------------------------------------------
// PIVILOCATIONS
// ----------------------------------------------------------------------
// Make query for pivilocations
$pivilocationquery = "INSERT INTO pivilocations ".
"(Category_name, Entityid, Level) ".
"VALUES ('~~~~~', '".$entityid."', '".$level."')";
// Run query
$pivilocationqueryrun = mysql_query($pivilocationquery);
// Check for success
if ($pivilocationqueryrun == FALSE) {
$dbstring = $dbstring."pivilocations=FAILED, ";
$dberror++;
} else {
$dbstring = $dbstring."pivilocations=WORKED, ";
}
// ----------------------------------------------------------------------
// PIVIENAMESDESC (language specific)
// ----------------------------------------------------------------------
// Run loop for all language specific entries into name tables
while ($namecounter != count($langarray)) {
// Make language specific table name
$nametable = "pivinamesdesc_".$langarray[$namecounter];
// Make query
$pivinamequery = "INSERT INTO ".$nametable.
" (Name, Description, Entityid, Level) VALUES ".
"('~~~~~', '', '".$entityid."', '".$level."')";
// Run query
$pivinamequeryrun = mysql_query($pivinamequery);
// Check for success
if ($pivinamequeryrun == FALSE) {
$dbstring = $dbstring.$nametable."=FAILED ";
$dberror++;
} else {
$dbstring = $dbstring.$nametable."=WORKED ";
}
// Increase counter for next language table
$namecounter++;
}
// Reset namecounter
$namecounter = 0;
// Finally increase counter for next picture
$addcounter++;
// Close paragrpah for $dbstring
$dbstring = $dbstring."</p>\n";
}
// Close database link
mysql_close($pivilink);
// Clean up temp files
rmdirtree($sessiondir.DIRECTORY_SEPARATOR);
// Calculate time for process, $endtime will be time in seconds
$endtime = (microtime(true) - $starttime);
// Show general stats
if ($genstats == 1) {
$filesworked = $counter - $fileerror;
echo "<p
class=\"center\">=====================================================</p>\n".
"<p class=\"center\">Total processing time: ".$endtime."
seconds.</p>\n".
"<p class=\"center\">Files processed: ".$counter." files.</p>\n".
"<p class=\"center\">Files added: ".$filesworked." files.</p>\n".
"<p class=\"center\">Files failed: ".$fileerror." files.</p>\n".
"<p class=\"center\">Database errors: ".$dberror." errors.</p>\n".
"<p class=\"center\">Average processing time for all files:
".($endtime / $counter)." seconds per file.</p>\n".
"<p class=\"center\">Average processing time for all added files:
".($endtime / $filesworked)." seconds per file.</p>\n";
}
// Show file stats
if ($filestats == 1) {
echo "<p
class=\"center\">=====================================================</p>\n".
$filestring;
}
// Show dbstats
if ($dbstats == 1) {
echo "<p
class=\"center\">=====================================================</p>\n".
$dbstring;
}
// Show some form to return to adminwelcome
echo "<form method=\"POST\" action=\"".
$_SESSION['sessionredirectpath']."/administration/adminwelcome.php\">\n";
echo "<p class=\"center\"> <input type=\"submit\" value=\"Return to
Welcome Page\" />";
echo "</form>";
?>
</body>
</html>
_______________________________________________
New York PHP Community Talk Mailing List
http://lists.nyphp.org/mailman/listinfo/talk
NYPHPCon 2006 Presentations Online
http://www.nyphpcon.com
Show Your Participation in New York PHP
http://www.nyphp.org/show_participation.php