Ver Mensaje Individual
  #6 (permalink)  
Antiguo 10/03/2010, 13:48
flashtkd
 
Fecha de Ingreso: agosto-2008
Mensajes: 587
Antigüedad: 15 años, 9 meses
Puntos: 6
Respuesta: obtener variable de subida de file ?

acá tengo otro ejemplo que registra los proceso de subida, NO esta creado con flash, ni flex, ni javaFX, ni tampoco con applet, ni mucho menos con silverlight, lo datos de salida son tan precisos y en tiempo real que comprueba que es posible.

acá tengo el archivo en PHP descargar codigo



Parte 1 - no me cae todo el código en el post.
Código PHP:
Ver original
  1. <?php
  2.  
  3. $db_server   = 'localhost';
  4. $db_name     = '';
  5. $db_username = '';
  6. $db_password = '';
  7.  
  8. // Other settings (optional)
  9.  
  10. $filename           = '';     // Specify the dump filename to suppress the file selection dialog
  11. $csv_insert_table   = '';     // Destination table for CSV files
  12. $csv_preempty_table = false;  // true: delete all entries from table specified in $csv_insert_table before processing
  13. $ajax               = true;   // AJAX mode: import will be done without refreshing the website
  14. $linespersession    = 3000;   // Lines to be executed per one import session
  15. $delaypersession    = 0;      // You can specify a sleep time in milliseconds after each session
  16.                               // Works only if JavaScript is activated. Use to reduce server overrun
  17.  
  18. // Allowed comment delimiters: lines starting with these strings will be dropped by BigDump
  19.  
  20. $comment[]='#';                       // Standard comment lines are dropped by default
  21. $comment[]='-- ';
  22. // $comment[]='---';                  // Uncomment this line if using proprietary dump created by outdated mysqldump
  23. // $comment[]='CREATE DATABASE';      // Uncomment this line if your dump contains create database queries in order to ignore them
  24. $comment[]='/*!';                  // Or add your own string to leave out other proprietary things
  25.  
  26.  
  27.  
  28. // Connection character set should be the same as the dump file character set (utf8, latin1, cp1251, koi8r etc.)
  29. // See http://dev.mysql.com/doc/refman/5.0/en/charset-charsets.html for the full list
  30.  
  31. $db_connection_charset = '';
  32.  
  33.  
  34. // *******************************************************************************************
  35. // If not familiar with PHP please don't change anything below this line
  36. // *******************************************************************************************
  37.  
  38. if ($ajax)
  39.   ob_start();
  40.  
  41. define ('VERSION','0.32b');
  42. define ('DATA_CHUNK_LENGTH',16384);  // How many chars are read per time
  43. define ('MAX_QUERY_LINES',300);      // How many lines may be considered to be one query (except text lines)
  44. define ('TESTMODE',false);           // Set to true to process the file without actually accessing the database
  45.  
  46. header("Expires: Mon, 1 Dec 2003 01:00:00 GMT");
  47. header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");
  48. header("Cache-Control: no-store, no-cache, must-revalidate");
  49. header("Cache-Control: post-check=0, pre-check=0", false);
  50. header("Pragma: no-cache");
  51.  
  52. @ini_set('auto_detect_line_endings', true);
  53.  
  54. if (function_exists("date_default_timezone_set") && function_exists("date_default_timezone_get"))
  55.  
  56. // Clean and strip anything we don't want from user's input [0.27b]
  57.  
  58. foreach ($_REQUEST as $key => $val)
  59. {
  60.   $val = preg_replace("/[^_A-Za-z0-9-\.&= ]/i",'', $val);
  61.   $_REQUEST[$key] = $val;
  62. }
  63.  
  64. ?>
  65. <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
  66. <html>
  67. <head>
  68. <title>BigDump ver. <?php echo (VERSION); ?></title>
  69. <meta http-equiv="CONTENT-TYPE" content="text/html; charset=iso-8859-1"/>
  70. <meta http-equiv="CONTENT-LANGUAGE" content="EN"/>
  71.  
  72. <meta http-equiv="Cache-Control" content="no-cache/"/>
  73. <meta http-equiv="Pragma" content="no-cache"/>
  74. <meta http-equiv="Expires" content="-1"/>
  75.  
  76. <style type="text/css">
  77. <!--
  78.  
  79. body
  80. { background-color:#FFFFF0;
  81. }
  82.  
  83. h1
  84. { font-size:20px;
  85.   line-height:24px;
  86.   font-family:Arial,Helvetica,sans-serif;
  87.   margin-top:5px;
  88.   margin-bottom:5px;
  89. }
  90.  
  91. p,td,th
  92. { font-size:14px;
  93.   line-height:18px;
  94.   font-family:Arial,Helvetica,sans-serif;
  95.   margin-top:5px;
  96.   margin-bottom:5px;
  97.   text-align:justify;
  98.   vertical-align:top;
  99. }
  100.  
  101. p.centr
  102. {
  103.   text-align:center;
  104. }
  105.  
  106. p.smlcentr
  107. { font-size:10px;
  108.   line-height:14px;
  109.   text-align:center;
  110. }
  111.  
  112. p.error
  113. { color:#FF0000;
  114.   font-weight:bold;
  115. }
  116.  
  117. p.success
  118. { color:#00DD00;
  119.   font-weight:bold;
  120. }
  121.  
  122. p.successcentr
  123. { color:#00DD00;
  124.   background-color:#DDDDFF;
  125.   font-weight:bold;
  126.   text-align:center;
  127. }
  128.  
  129. td
  130. { background-color:#F8F8F8;
  131.   text-align:left;
  132. }
  133.  
  134. td.transparent
  135. { background-color:#FFFFF0;
  136. }
  137.  
  138. th
  139. { font-weight:bold;
  140.   color:#FFFFFF;
  141.   background-color:#AAAAEE;
  142.   text-align:left;
  143. }
  144.  
  145. td.right
  146. { text-align:right;
  147. }
  148.  
  149. form
  150. { margin-top:5px;
  151.   margin-bottom:5px;
  152. }
  153.  
  154. div.skin1
  155. {
  156.   border-color:#3333EE;
  157.   border-width:5px;
  158.   border-style:solid;
  159.   background-color:#AAAAEE;
  160.   text-align:center;
  161.   vertical-align:middle;
  162.   padding:3px;
  163.   margin:1px;
  164. }
  165.  
  166. td.bg3
  167. { background-color:#EEEE99;
  168.   text-align:left;
  169.   vertical-align:top;
  170.   width:20%;
  171. }
  172.  
  173. th.bg4
  174. { background-color:#EEAA55;
  175.   text-align:left;
  176.   vertical-align:top;
  177.   width:20%;
  178. }
  179.  
  180. td.bgpctbar
  181. { background-color:#EEEEAA;
  182.   text-align:left;
  183.   vertical-align:middle;
  184.   width:80%;
  185. }
  186.  
  187. -->
  188. </style>
  189.  
  190. </head>
  191.  
  192. <body>
  193.  
  194. <center>
  195.  
  196. <table width="780" cellspacing="0" cellpadding="0">
  197. <tr><td class="transparent">
  198.  
  199. <!-- <h1>BigDump: Staggered MySQL Dump Importer ver. <?php echo (VERSION); ?></h1> -->
  200.  
  201. <?php
  202.  
  203. function skin_open() {
  204. echo ('<div class="skin1">');
  205. }
  206.  
  207. function skin_close() {
  208. echo ('</div>');
  209. }
  210.  
  211. skin_open();
  212. echo ('<h1>BigDump: Staggered MySQL Dump Importer v'.VERSION.'</h1>');
  213. skin_close();
  214.  
  215. $error = false;
  216. $file  = false;
  217.  
  218. // Check PHP version
  219.  
  220. if (!$error && !function_exists('version_compare'))
  221. { echo ("<p class=\"error\">PHP version 4.1.0 is required for BigDump to proceed. You have PHP ".phpversion()." installed. Sorry!</p>\n");
  222.   $error=true;
  223. }
  224.  
  225. // Check if mysql extension is available
  226.  
  227. if (!$error && !function_exists('mysql_connect'))
  228. { echo ("<p class=\"error\">There is no mySQL extension available in your PHP installation. Sorry!</p>\n");
  229.   $error=true;
  230. }
  231.  
  232. // Calculate PHP max upload size (handle settings like 10M or 100K)
  233.  
  234. if (!$error)
  235. { $upload_max_filesize=ini_get("upload_max_filesize");
  236.   if (preg_match("/([0-9]+)K/i",$upload_max_filesize,$tempregs)) $upload_max_filesize=$tempregs[1]*1024;
  237.   if (preg_match("/([0-9]+)M/i",$upload_max_filesize,$tempregs)) $upload_max_filesize=$tempregs[1]*1024*1024;
  238.   if (preg_match("/([0-9]+)G/i",$upload_max_filesize,$tempregs)) $upload_max_filesize=$tempregs[1]*1024*1024*1024;
  239. }
  240.  
  241. // Get the current directory
  242.  
  243. if (isset($_SERVER["CGIA"]))
  244.   $upload_dir=dirname($_SERVER["CGIA"]);
  245. else if (isset($_SERVER["ORIG_PATH_TRANSLATED"]))
  246.   $upload_dir=dirname($_SERVER["ORIG_PATH_TRANSLATED"]);
  247. else if (isset($_SERVER["ORIG_SCRIPT_FILENAME"]))
  248.   $upload_dir=dirname($_SERVER["ORIG_SCRIPT_FILENAME"]);
  249. else if (isset($_SERVER["PATH_TRANSLATED"]))
  250.   $upload_dir=dirname($_SERVER["PATH_TRANSLATED"]);
  251. else
  252.   $upload_dir=dirname($_SERVER["SCRIPT_FILENAME"]);
  253.  
  254. // Handle file upload
  255.  
  256. if (!$error && isset($_REQUEST["uploadbutton"]))
  257. { if (is_uploaded_file($_FILES["dumpfile"]["tmp_name"]) && ($_FILES["dumpfile"]["error"])==0)
  258.   {
  259.     $uploaded_filename=str_replace(" ","_",$_FILES["dumpfile"]["name"]);
  260.     $uploaded_filename=preg_replace("/[^_A-Za-z0-9-\.]/i",'',$uploaded_filename);
  261.     $uploaded_filepath=str_replace("\\","/",$upload_dir."/".$uploaded_filename);
  262.  
  263.     if (file_exists($uploaded_filename))
  264.     { echo ("<p class=\"error\">File $uploaded_filename already exist! Delete and upload again!</p>\n");
  265.     }
  266.     else if (!preg_match("/(\.(sql|gz|csv))$/i",$uploaded_filename))
  267.     { echo ("<p class=\"error\">You may only upload .sql .gz or .csv files.</p>\n");
  268.     }
  269.     else if (!@move_uploaded_file($_FILES["dumpfile"]["tmp_name"],$uploaded_filepath))
  270.     { echo ("<p class=\"error\">Error moving uploaded file ".$_FILES["dumpfile"]["tmp_name"]." to the $uploaded_filepath</p>\n");
  271.       echo ("<p>Check the directory permissions for $upload_dir (must be 777)!</p>\n");
  272.     }
  273.     else
  274.     { echo ("<p class=\"success\">Uploaded file saved as $uploaded_filename</p>\n");
  275.     }
  276.   }
  277.   else
  278.   { echo ("<p class=\"error\">Error uploading file ".$_FILES["dumpfile"]["name"]."</p>\n");
  279.   }
  280. }
  281.  
  282.  
  283. // Handle file deletion (delete only in the current directory for security reasons)
  284.  
  285. if (!$error && isset($_REQUEST["delete"]) && $_REQUEST["delete"]!=basename($_SERVER["SCRIPT_FILENAME"]))
  286. { if (preg_match("/(\.(sql|gz|csv))$/i",$_REQUEST["delete"]) && @unlink(basename($_REQUEST["delete"])))
  287.     echo ("<p class=\"success\">".$_REQUEST["delete"]." was removed successfully</p>\n");
  288.   else
  289.     echo ("<p class=\"error\">Can't remove ".$_REQUEST["delete"]."</p>\n");
  290. }
  291.  
  292. // Connect to the database
  293.  
  294. if (!$error && !TESTMODE)
  295. { $dbconnection = @mysql_connect($db_server,$db_username,$db_password);
  296.   if ($dbconnection)
  297.     $db = mysql_select_db($db_name);
  298.   if (!$dbconnection || !$db)
  299.   { echo ("<p class=\"error\">Database connection failed due to ".mysql_error()."</p>\n");
  300.     echo ("<p>Edit the database settings in ".$_SERVER["SCRIPT_FILENAME"]." or contact your database provider.</p>\n");
  301.     $error=true;
  302.   }
  303.   if (!$error && $db_connection_charset!=='')
  304.     @mysql_query("SET NAMES $db_connection_charset", $dbconnection);
  305. }
  306. else
  307. { $dbconnection = false;
  308. }
  309.  
  310. // echo("<h1>Checkpoint!</h1>");
  311.  
  312. // List uploaded files in multifile mode
  313.  
  314. if (!$error && !isset($_REQUEST["fn"]) && $filename=="")
  315. { if ($dirhandle = opendir($upload_dir))
  316.   { $dirhead=false;
  317.     while (false !== ($dirfile = readdir($dirhandle)))
  318.     { if ($dirfile != "." && $dirfile != ".." && $dirfile!=basename($_SERVER["SCRIPT_FILENAME"]))
  319.       { if (!$dirhead)
  320.         { echo ("<table width=\"100%\" cellspacing=\"2\" cellpadding=\"2\">\n");
  321.           echo ("<tr><th>Filename</th><th>Size</th><th>Date&amp;Time</th><th>Type</th><th>&nbsp;</th><th>&nbsp;</th>\n");
  322.           $dirhead=true;
  323.         }
  324.         echo ("<tr><td>$dir

Última edición por flashtkd; 10/03/2010 a las 13:55