Location: PHPKode > projects > Netautor Professional > netautor/napro4/appl/mediapool/mp_upload.php
<?php
/* +----------------------------------------------------------------------+
   | Netautor Professional Application Server                             |
   +----------------------------------------------------------------------+
   | Copyright (C) 1998-2005 digiconcept GmbH. <www.digiconcept.net>      |
   +----------------------------------------------------------------------+
   | This file is subject to license, that is bundled with this package   |
   | in the file LICENSE.TXT, and is available at through the             |
   | world-wide-web at http://www.netautor.com/license/                   |
   |                                                                      |
   | If you did not receive a copy of the license and are unable to       |
   | obtain it through the world-wide-web, please send a note to          |
   | hide@address.com so we can mail you a copy.                      |
   +----------------------------------------------------------------------+
   | Authors: Stefan Rottensteiner <hide@address.com>    |
   |          Marek  Kadziela      <hide@address.com>	      |
   |          Gregor Wollner                                              |
   |          Christian Unger                                             |
   |          Helli  Kleinhans  									      |
   +----------------------------------------------------------------------+*/

   /**
    * Eigentliche Uploadseite für den Medienpool
	*
	* @version 	$Revision: 1.11 $
	* @author	Stefan Rottensteiner
	*/

  	require_once('../../include/init.inc');

	if(!$USER->check_feature('Admin') && !$USER->check_feature('ac_mediapool'))
	{
		$USER->login_call();
	}

	$LOCALE->textdomain('mediapool');

	$max_uploads		= intval($_POST['max_uploads']);
	if (empty($max_uploads)) $max_uploads=5;
	//	include necessary functions
	includeNaPro('filetype,file,array');

?><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
	<title>/digiconcept/netautor/mediapool/upload.action</title>
	<link href="../../include/netautor.css" rel="stylesheet" type="text/css" src="../include/netautor.css">
</head>
<body class="imagepoollist">
<?php

	if (strlen(strval(ob_get_contents())) != 0) ob_end_flush();

	/**
	 * Basispfad zum Upload aus den POST oder GET Variablen ziehen
	 */
	@$DEF_UPLOAD_PATH	= str_replace('\\','/',strval($_POST['DEF_UPLOAD_PATH']));
	if (empty($DEF_UPLOAD_PATH)) @$DEF_UPLOAD_PATH	= str_replace('\\','/',strval($_GET['DEF_UPLOAD_PATH']));
	if (substr($DEF_UPLOAD_PATH,-1) != '/') $DEF_UPLOAD_PATH.='/';

	/**
	 * Bestimmtes RUNSCRIPT aus den POST oder GET Variabln ziehen
	 */
	@$DEF_UPLOAD_RUNSCRIPT	= strval($_POST['DEF_UPLOAD_RUNSCRIPT']);
	if (empty($DEF_UPLOAD_RUNSCRIPT)) @$DEF_UPLOAD_RUNSCRIPT	= strval($_GET['DEF_UPLOAD_RUNSCRIPT']);

	/**
	 * Wurden Files hinaufgeladen ?
	*/
	if (!empty($_FILES))
	{
		includeNaPro('string');

		/* Translator-Array für RUNSCRIPT  */
		$translator	= array	(	'SERVER_NAME'	=> $_SERVER['SERVER_NAME'],
								'SERVER_PORT'	=> $_SERVER['SERVER_PORT'],
								'SERVER_ADDRESS'=> $_SERVER['SERVER_ADDR'],
								'TIMESTAMP' 	=> time(),
								'DAY'			=> date('d'),'MONTH'	=> date('m'),'YEAR'		=> date('Y') ,
								'HOUR'			=> date('H'),'MINUTE'	=> date('i'),'SECOND'	=> date('s')
								);

		/**
		 * Ein bestimmtes RUNSCRIPT oder ALLE
		 */
		$runscript_to_use	= array();

		if (!empty($DEF_UPLOAD_RUNSCRIPT))
		{
			$run_script	= $GLOBALS['USER']->get_feature_value('run_script' ,  $DEF_UPLOAD_RUNSCRIPT );
			if (!empty($run_script[ key($run_script) ]))
			{
				$run_script = strval ($run_script[ key($run_script) ]);

				$match	= array();
				if (preg_match('/([a-z0-9_ ]+)=(.*)/i',$run_script,$match))
				{
					$runscript_to_use[] = magicReplacer($match[2],$translator);
				}
				else
				{
					$runscript_to_use[] = magicReplacer($run_script,$translator);
				}
			}
		}
		else
		{
			$run_script_array	= $GLOBALS['USER']->get_feature_value('run_script' );

			foreach ($run_script_array as $index => $run_script )
			{
				$match	= array();
				if (preg_match('/([a-z0-9_ ]+)=(.*)/i',$run_script,$match))
				{
					$runscript_to_use[] = magicReplacer($match[2],$translator);
				}
				else
				{
					$runscript_to_use[] = magicReplacer($run_script,$translator);
				}
			}
		}

		/* Upload-File-Array durchgehen */
		foreach ($_FILES['upload']['name'] as $INDEX => $original_filename)
		{
			@set_time_limit(0);
			$original_filesize	= $_FILES['upload']['name'][$INDEX];
			$upload_filepath	= $_FILES['upload']['tmp_name'][$INDEX];
			$upload_filename	= basename($upload_filepath);
			$upload_error		= $_FILES['upload']['error'][$INDEX];

			/* Irgendwas stimmt mit dem File nicht - Fehler setzten */
			if (!is_uploaded_file($upload_filepath)) $upload_error = 10;

			/* Fehlerhafter Upload ? Dann weiter */
			if (!empty($upload_error)) {
				echo "<!-- Error $upload_error while handling uploaded file [$upload_filepath] -->";
				$_FILES['upload']['error'][$INDEX]	= $upload_error;
				continue;
			}

			$upload_target_filepath	= $DEF_UPLOAD_PATH.$original_filename;
			echo "<!-- Copy from [$upload_filepath] to [$upload_target_filepath] -->";
			flush();

			if (!move_uploaded_file($upload_filepath,$upload_target_filepath))
			{
				/* Beim Kopieren des Files ist etwas schief gegagen - Fehler setzen und weiter */
				echo "<!-- Error 11 while handling uploaded file [$upload_filepath] -->";
				flush();

				$_FILES['upload']['error'][$INDEX]	= 11;
				continue;
			}
			else
			{
				$_FILES['upload']['error'][ $INDEX ]	= -1;
				$_FILES['upload']['targetfile'][ $INDEX ]	= $upload_target_filepath;
				/**
				 * File kopiert, nun jedes notwendige RUN_SCRIPT aufrufen
				 */
				foreach ($runscript_to_use as $index => $run_script) {
					if (empty($run_script)) continue;
					 @set_time_limit(0);
					echo "<!-- Call [$run_script] for file [$upload_target_filepath] -->";
					flush();
				}
			}
		}


	}

?>
<script>

function checkNumberOfUploads()
{
	numberOfUploads = parseInt(document.getElementById('NUMBER_OF_UPLOADS').value);
	maxUploads 		= parseInt(document.getElementById('MAX_UPLOADS').value);

    if(numberOfUploads>=maxUploads)
        document.getElementById('addimage').style.visibility = 'hidden';
	else
        document.getElementById('addimage').style.visibility = 'visible';

	if(numberOfUploads >= 1)
        document.getElementById('removeimage').style.display = 'inline';
	else
        document.getElementById('removeimage').style.display = 'none';

}

function addTab()
{
	numberOfUploads = parseInt(document.getElementById('NUMBER_OF_UPLOADS').value);
	maxUploads 		= parseInt(document.getElementById('MAX_UPLOADS').value);


	newNumber = numberOfUploads + 1;

	myClone = document.getElementById('uploadtap0').cloneNode(true);
    myClone.setAttribute('id','uploadtap'+newNumber);

    document.getElementById('uploadTable').appendChild(myClone);
	document.getElementById('NUMBER_OF_UPLOADS').value = newNumber;

	checkNumberOfUploads();
}

function removeTab()
{
    numberOfUploads = parseInt(document.getElementById('NUMBER_OF_UPLOADS').value);
	newNumber = numberOfUploads - 1;

	myNode = document.getElementById('uploadtap'+numberOfUploads);

	document.getElementById('uploadTable').removeChild(myNode);
    document.getElementById('NUMBER_OF_UPLOADS').value = newNumber;

	checkNumberOfUploads();
}

</script>
<div style="position:absolute; top:20px; left:640px" id="plusminus">
	<img src="../../grafik/na_plus.gif" 	border="0" onclick="addTab()" 		id="addimage"		style="display:inline;">
	<img src="../../grafik/na_minus.gif" 	border="0" onclick="removeTab()" 	id="removeimage" 	style="display:none;">
</div>
<form action="mp_upload.php" method="post" enctype="multipart/form-data" name="mp_form_upload" id="mp_form_upload">
<input type="hidden" name="max_uploads"			id="MAX_UPLOADS" 			value="<?php echo $max_uploads; ?>" 	 		>
<input type="hidden" name="clear_upload"			id="CLEAR_UPLOAD" 			value="" 								 	>
<input type="hidden" name="numberOfUploads" 		id="NUMBER_OF_UPLOADS"		value="0">
<input type="hidden" name="DEF_UPLOAD_PATH" 		id="DEF_UPLOAD_PATH" 		value="">
<input type="hidden" name="DEF_UPLOAD_RUNSCRIPT" 	id="DEF_UPLOAD_RUNSCRIPT" 	value="">

<table border="0" cellspacing="0" cellpadding="0" >
	<tbody id="uploadTable">
	<tr height="60" id="uploadtap0">
		<td width="24" height="60" align="center" valign="center" class="imgpooltd22">
			<img src="../../grafik/pixel.gif" width="24" height="1"><br>
		</td>
		<td width="78" height="60" align="center" valign="center" class="imgpooltd21">
			<img src="../../grafik/pixel.gif" width="50" height="50" class="imgpoolimg"><br>
		</td>
		<td width="522" height="60" align="left" valign="middle" class="imgpooltd22">
				<img src="../../grafik/pixel.gif" width="12" height="1">
				<input name="upload[]" type="file" class="input386"><br>
				<img src="../../grafik/pixel.gif" width="522" height="1"><br>
		</td>
		<td width="60" height="60" align="left" valign="center" class="imgpooltd21">

		</td>
	</tr>
	</tbody>
</table>
<?
	if(!empty($_FILES))
	{	?>
		<table border="0" cellspacing="0" cellpadding="0">
		<tbody>
		<tr>
			<td width="24" height="60" align="center" valign="center" class="imgpooltd21">
				<img src="../../grafik/pixel.gif" width="24" height="1"><br>
			</td>
			<td class="imgpooltd21" colspan="3">
				<span class="text">&nbsp;&nbsp;<b>Daten des letzten Uploads</b></span>
			</td>
		</tr>
		<?php
		foreach($_FILES['upload']['name'] as $i=>$original_filename)
		{
			?>
			<tr height="60">
				<td width="24" height="60" align="center" valign="center" class="imgpooltd22">
					<img src="../../grafik/pixel.gif" width="24" height="1"><br>
				</td>
				<td width="78" height="60" align="center" valign="center" class="imgpooltd21">
					<?
                    	if(empty($_FILES['upload']['targetfile'][$i]))
						{
							echo('<img src="../../grafik/pixel.gif" width="50" height="50" class="imgpoolimg"><br>');
						}
						else
						{
							echo('<img src="'.$GLOBALS['DC_ENV']->indexpath.'/wrapper/jpegs.php?filename='.rawurlencode($_FILES['upload']['targetfile'][$i]).'" width="50" height="50" class="imgpoolimg"><br>');
						}
					?>
				</td>
				<td width="522" height="60" align="center" valign="middle" class="imgpooltd22">
					<span class="text">
			<?php
				if($_FILES['upload']['error'][ $i ]<=0)
				{
					echo( $LOCALE->gettext('msg_upload_okay',array($original_filename)) );
				}
				else
				{
					echo( $LOCALE->gettext('msg_upload_failed',array($_FILES['upload']['error'][ $i ],$original_filename)) );
				}
			?>
					</span>
				</td>
				<td width="60" height="60" align="left" valign="center" class="imgpooltd21">

				</td>
			</tr>
<?		}	?>
		</tbody>
		</table>
<?	}	?>
</form>
</body>

</html>
Return current item: Netautor Professional