DIrk H.: Javascript Ajax Upload Sonderzeichen

Beitrag lesen

Hier ein paar Zeilen code...

upload.php:

<?PHP

	header("Content-Type: text/html; charset=utf-8");


	if( $_GET["testData"] )

			$DATA = $_GET["testData"];
	else
			$DATA = 'Täst';

	
	
	echo "	<HTML>
			
			<HEAD>
			
			<SCRIPT>


			function filelistChange()
			{
				var fileList = document.getElementById('fileA').files;

				var file = fileList[0];

				
				document.getElementById('fileinfo').innerHTML = file.type + ' - ' + parseInt(file.size/1024) + 'kb';
				document.getElementById('files_result_output').style.display = 'block';

				

				var formData = new FormData();

				client = new XMLHttpRequest();


				var prog = document.getElementById('progress');
				prog.value = 0;
				prog.max = 100;

				var proz = document.getElementById('prozent');				
				proz.innerHTML = '0%';


				
				formData.append('datei', file );
				formData.append('testData', file.name );

				


				client.onerror = function(e) {
				
					alert( e );
				};

				client.onload = function(e) {

					proz.innerHTML = '100%';
					prog.value = prog.max;

					location.href = 'upload.php?action=done';
				};

				client.upload.onprogress = function(e) {

					var p = Math.round(100 / e.total * e.loaded);
					prog.value = p;            
					proz.innerHTML = p + '%';
				};

				client.onabort = function(e) {
	
					prog.value =   0;
					prog.max   = 100;
					document.getElementById('prozent').innerHTML = '0%';					
				};

				client.open('POST', 'uploadFile.php');
				client.send(formData);

			}
			
			</SCRIPT>
							
			</HEAD>

			<BODY>

			<FORM>

				<INPUT id='testData' name='testData' value='" . $DATA . "'>
			
				<INPUT type='file' id='fileA' onChange='filelistChange()'>
		
				<INPUT type='submit'>


				<DIV id='files_result_output' style='display:none'>
					<span id='fileinfo'></span>
					<progress id='progress'></progress> <span id='prozent'></span>
				</DIV>
	
			</FORM>

			</BODY>
			
			</HTML>";

?>

uploadFile.php:

<?PHP

	header("Content-Type: text/html; charset=utf-8");

	
  
	$f = fopen("uploadFile.log","w");


 		
				
		$ORG = $_FILES['datei']['tmp_name'];
		$DST = $_FILES['datei']['name'];
		$TST = $_POST["testData"];

		fwrite($f,"org=" . $ORG . "\n" );
		fwrite($f,"dst=" . $DST . "\n" );
		
		fwrite($f,"tst=" . utf8_decode( $TST ) . "\n" );
	
	
		fclose($f);

?>