<?php
/*
Uploadify
Copyright (c) 2012 Reactive Apps, Ronnie Garcia
Released under the MIT License <http://www.opensource.org/licenses/mit-license.php> 
*/

// Define a destination
$targetFolder = '/pdf'; // Relative to the root

//检测文档是否存在
//if(is_exit())

if (!empty($_FILES)) {
	$tempFile = $_FILES['Filedata']['tmp_name'];
	$targetPath = "../" . $targetFolder;
	

	// Validate the file type
	$fileTypes = array('pdf','PDF'); // File extensions
	$fileParts = pathinfo($_FILES['Filedata']['name']);
    
	//检测文档是否错误
	if(error($_FILES['Filedata']['error']) != '1')
	{
	  
	
	
	if (in_array($fileParts['extension'],$fileTypes)) {
      $_FILES['Filedata']['name'] = "DWZ".date("YmdHis").".".$fileParts['extension'];
	  $targetFile = rtrim($targetPath,'/') . '/' . $_FILES['Filedata']['name']; 
	if(is_uploaded_file($tempFile))
	{
		move_uploaded_file($tempFile,$targetFile);
		echo $targetFolder . '/' . $_FILES['Filedata']['name'];
	
      }else{
	   echo '1';
	 }
	}else {
		echo '0';
	}
  }
}

function error($errorNo) {
         switch($errorNo) {
            case 1:
                echo '上传的文件超过了 php.ini 中 upload_max_filesize 选项限制的值';
                break;
            case 2:
                echo '上传文件的大小超过了 HTML 表单中 MAX_FILE_SIZE 选项指定的值';
                break;
            case 3:
                echo '文件只有部分被上传';
                break;
            case 4:
                echo '没有文件被上传';
                break;
            case 6:
                echo '找不到临时文件夹';
                break;
            case 7:
                echo '文件写入失败';
                break;
        }
    }
?>