$extension) { if (EndsWith($_FILES['Filedata']['name'],$extension)){ $allowed=true; break; } } if (!$allowed){ //we tell the swf this extension is not allowed echo( '?result=notallowed'); }else { if ((!file_exists($uploadfile) || (file_exists($uploadfile) AND filesize($uploadfile) == filesize($_FILES["Filedata"]["tmp_name"]))) ) { //if the file does not exists or if it exists and its the same file if (move_uploaded_file( $_FILES['Filedata']['tmp_name'] , $uploadfile ) ) { //if the file is moved successfully we return a success message echo( '?result=success&fileurl='. $UploadFolderURL."/". $_FILES['Filedata']['name']); }else{ //file failed to move echo( '?result=fail'); } }else{ //if a file with the same name exists, we rename the one that is being uploaded $uploadfile = $storage."/" . basename( $_FILES["Filedata"]["name"] ); $path_parts = pathinfo($uploadfile); $i = 0; do { $i++; }while (file_exists($storage."/".$path_parts["filename"]." (".$i.")".".".$path_parts["extension"]) AND filesize($storage."/".$path_parts["filename"]." (".$i.")".".".$path_parts["extension"]) != filesize($_FILES["Filedata"]["tmp_name"]) ); $uploadfile = $storage."/".$path_parts["filename"]." (".$i.")".".".$path_parts["extension"]; if(move_uploaded_file( $_FILES["Filedata"]["tmp_name"] , $uploadfile)){ echo( '?result=success&fileurl='. $UploadFolderURL."/". $path_parts["filename"]." (".$i.")".".".$path_parts["extension"]); }else{ //file failed to move echo( '?result=fail'); } } } } ?>