<?php
/*
Uploadify v2.1.4
Release Date: November 8, 2010

Copyright (c) 2010 Ronnie Garcia, Travis Nickels

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
*/
if (!empty($_FILES)) {
	$tempFile   = $_FILES['Filedata']['tmp_name'];
	$targetPath = $_SERVER['DOCUMENT_ROOT'] . $_REQUEST['folder'] . '/';

	// ext
	$p = pathinfo($_FILES['Filedata']['name']);
	$ext = '.'.$p['extension'];
	$_FILES['Filedata']['ext'] = $ext;

	$targetFile =  str_replace('//','/',$targetPath).$_FILES['Filedata']['name'];
	$targetFile =  str_replace('//','/',$targetPath).basename($_FILES['Filedata']['tmp_name']);
	$targetFile =  str_replace('//','/',$targetPath).basename($_FILES['Filedata']['tmp_name']).$ext;

	// uploaded_name
	$basename = basename($_FILES['Filedata']['tmp_name'].$_FILES['Filedata']['ext']);
/*
	$uploaded_name = $_SERVER['DOCUMENT_ROOT'].$_REQUEST['folder'].'/'.$_FILES['Filedata']['tmp_name'].$_FILES['Filedata']['ext'];
	$uploaded_name = str_replace('/./','/',$uploaded_name);
	$uploaded_name = str_replace('//','/',$uploaded_name);
*/
	//move_uploaded_file($tempFile,$uploaded_name);
	move_uploaded_file($tempFile,$targetFile);

//	$_FILES['Filedata']['uploaded_name']     = $uploaded_name;
	$_FILES['Filedata']['uploadify_name']     = $targetFile;
	$_FILES['Filedata']['uploadify_basename'] = $basename;

	$rnd_key;
	if (isset($_REQUEST['rnd_key'])){ $rnd_key = $_REQUEST['rnd_key']; }
	else{ $rnd_key = 'no_key'; }
	$fp = fopen($targetPath.$rnd_key.'.txt', "a");
	fputs($fp, serialize($_FILES['Filedata'])."\n");
	fclose($fp);
	echo "1";

}
?>