![Antiguo](http://static.forosdelweb.com/fdwtheme/images/statusicon/post_old.gif)
11/01/2010, 09:37
|
![Avatar de arielcasanova](http://static.forosdelweb.com/customavatars/avatar76805_1.gif) | | | Fecha de Ingreso: octubre-2004 Ubicación: Bahía Blanca - Argentina
Mensajes: 332
Antigüedad: 20 años, 4 meses Puntos: 1 | |
Respuesta: ¿como scanear una carpeta y cargar sus archivos en una db? tema resuelto:
Si no está entre "", no interpreta la variable como directorio cuando la paso por is_dir.
el código final me quedó así:
Código:
$the_array2 = array();
$handle2 = opendir("../fotos");
while (false !== ($carpeta = readdir($handle2))) {
if ($carpeta !="." and $carpeta!=".." and is_dir("../fotos/$carpeta")) {
$the_array2[] = $carpeta;
}
}
closedir($handle2);
sort ($the_array2);
foreach($the_array2 as $val2)
{
$the_array = array();
$handle = opendir("../fotos/$val2");
while (false !== ($file = readdir($handle))) {
if ($file != "." && $file != "..") {
$the_array[] = $file;
}
}
closedir($handle);
sort ($the_array);
foreach($the_array as $val)
{
/*SEPARAR FRAGMENTOS ARCHIVO*/
list($complejidad,$galeria,$nombre) = explode("-",$val);
switch ($complejidad)
{
case "A":
$complejidadn=1;
break;
case "B":
$complejidadn=1.5;
break;
case "C":
$complejidadn=2;
break;
case "D":
$complejidadn=2.5;
break;
case "E":
$complejidadn=3;
break;
}
/*COPIA LOS ARCHIVOS A LA RAÍZ*/
if (copy( "../fotos/$val2/$val", "../fotos/$val"))
{
/*ELIMINA LOS ARCHIVOS DE LA CARPETA*/
unlink("../fotos/$val2/$val");
}
/*INSERTA LOS REGISTROS EN LA DB*/
$sql="insert into tattoos_tattoos (imagen, galeria, nombre, complejidad)
values ('$val', '$galeria', '$nombre', '$complejidadn')";
if ($result= mysql_query($sql, $conexion))
{ echo $sql."<br/>"; }
}
if (rmdir("../fotos/$var2"))
{echo "$var2 elimnado <br>"; }
else
{echo "$var2 NO elimnado <br>"; }
/*GRABA LA GALERÍA EN LA DB*/
$sql = "SELECT distinct galeria FROM tattoos_tattoos";
$result = mysql_query($sql, $conexion);
if ($row = mysql_fetch_array($result)){
mysql_field_seek($result,0);
do {
$galeria=$row['galeria'];
$sqlar="insert into tattoos_galerias (imagen, nombre)
values ('nofoto.jpg', '$galeria')";
$resultar= mysql_query($sqlar, $conexion);
}
while ($row = mysql_fetch_array($result));
}
}
|