Ver Mensaje Individual
  #4 (permalink)  
Antiguo 01/10/2004, 07:25
satchb
 
Fecha de Ingreso: septiembre-2004
Ubicación: Puebla, México
Mensajes: 81
Antigüedad: 19 años, 6 meses
Puntos: 0
Que raro, yo si puedo... si no trata con php.net te metes a documentation, en view online escoge spanish y en la tabla de contenido escoge el 20. Manejo de envío de archivos.

Pero de todos modos ahi te va:

therebechips
06-Sep-2003 04:02
Re: Handling uploads and downloads of large files and storing in MySQL.

Use two tables to store data about the file and the file data itself. ***Important: to preserve the integrity of the data use base64_encode() NOT addslashes().
Código PHP:
<?php
// Max packet size
   
define("MAX_SQL",50000);
   
$filehandle fopen($tmp"rb") or die( "Can't open file!" );
   
$query=    "INSERT INTO files (name, type, size) VALUES(".
             
$DB->quote($name).", ".
             
$DB->quote($type).", ".
             
$DB->quote($size).
             
")";

   
// Execute Query
   
$result $DB->query($query);
   
$file_id mysql_insert_id();

// Copy the binary file data to the filedata table in sequential rows each containing MAX_SQL bytes
// Your table should have an index set to auto_increment
// Store the file_id to identify the data fragments
   
while (!feof ($filehandle)) {
       
$data base64_encode(fread($filehandle,MAX_SQL));
       
$query "INSERT INTO filedata (file_id, data) VALUES($file_id,\"".$data."\")";
       
$result $DB->query($query);
   }
   
fclose ($filehandle);
?>

Decode the data fragments and recombine them:
<?php
   $file_id 
=$_GET ['file_id'];
   
$query ="select file_id, name, type, size from files where file_id='$file_id'";
   
$result $DB->query($query);
   
$rowmysql_fetch_array ($result);
   
$type $row ["type"];
   
$name $row ["name"];
   
$size $row ["size"];
   
$file_id $row ["file_id"];

   
// get the file data
   
$query "select id, data from filedata where file_id='$file_id' ORDER by id";
   
$result $DB->query($query);

// decode the fragments and recombine the file
   
$data "";
   while (
$row mysql_fetch_array($result)) {
       
$data .= base64_decode($row ["data"]); 
   }
  
// output the file
   
header ("Content-type: $type");
   
header ("Content-length: $size");
   
header ("Content-Disposition: attachment; filename=$name");
   
header ("Content-Description: PHP Generated Data");
   echo 
$data;
?>
y

--HANDLING LARGE FILE UPLOADS and entering into a MySQL blob field--

Hope this helps someone as it was hard to fig out. MySQL default buffer and packets are set small. here is a method to get aroudn it.
Código PHP:
$filehandle fopen($addfile"r");
$filesize filesize($addfile);

//now this is bullshit, but have to read the file piece by piece and insert because the mysql server is set up to only handle 1meg inserts (small buffer and packet).

$buffer addslashes(fread($filehandle906240));
$query "Insert into files (file, filename, size, userid ) values ('$filedata','$addfile_name', '$filesize')";
$this->query($query);
$id mysql_insert_id($this->link_id());
        
while (!
feof ($filehandle)) {
  
$buffer addslashes(fread($filehandle906240));
  
$query "UPDATE files SET file = concat('$buffer') where id='$id'";
  
$this->query($query);
}
fclose ($filehandle); 
__________________
Revista DdS
Revista on-line sobre desarrollo de software