<?php
error_reporting(E_ALL);
	include_once( "f_admin.php" );
	include_once( "f_wfl.php" );
	
	//xlog( 4, json_encode( $_FILES ) );
	
	
	
	$f = file_get_contents( $_FILES[ "file" ][ "tmp_name" ][ 0 ] );
	/*
	if ( $f )
	{
		xlog( 4, "true" );
	}
	else
	{
		xlog( 4, "false" );
	}
	*/
	
	$tmpdir = $_SERVER["DOCUMENT_ROOT"]."/temp";
	
	$zaehler = 1;
	
	
	
	while ( file_exists( $tmpdir."/".$_POST[ "praefix_2" ]."_".$zaehler ) )
	{
		$zaehler = bcadd( $zaehler, 1, 0 );
	}
	
	$fh = fopen( $tmpdir."/".$_POST[ "praefix_2" ]."_".$zaehler, "wb" );
	$erg = fwrite( $fh, $f );
	fclose( $fh );
	
	$fh = fopen( $tmpdir."/".$_POST[ "praefix_2" ]."_".$zaehler.".info", "wb" );
	$erg = fwrite( $fh, json_encode( $_FILES ) );
	fclose( $fh );
	
	
	/*
	if ( file_exists( $datei[ 0 ] ) )
	{
		xlog( 4, "true" );
	}
	else
	{
		xlog( 4, "false" );
	}
	*/
	//sleep(20);
	echo '{"name":"'.$_FILES[ "file" ][ "name" ][ 0 ].' ('.number_format( $_FILES[ "file" ][ "size" ][ 0 ], 0, ",", "." ).' Bytes)","type":"image/jpeg","size":"'.$_FILES[ "file" ][ "size" ][ 0 ].'"}';
	
	
?>