Foros del Web » Programando para Internet » PHP »

Borrar los archivos de una carpeta al desconectar

Estas en el tema de Borrar los archivos de una carpeta al desconectar en el foro de PHP en Foros del Web. Hola: Estoy usando un script, una galeria de fotos que crea en una carpeta temporal las miniaturas de las imagenes grandes. Mi problema es que ...
  #1 (permalink)  
Antiguo 26/02/2004, 18:13
 
Fecha de Ingreso: abril-2003
Mensajes: 363
Antigüedad: 21 años
Puntos: 3
Borrar los archivos de una carpeta al desconectar

Hola:

Estoy usando un script, una galeria de fotos que crea en una carpeta temporal las miniaturas de las imagenes grandes. Mi problema es que el programa crea y crea archivos en el directorio temporal pero no les borra, necesito insertar una función a mi programilla para que me elimine todo el contenido de ese directorio temporal al salir de la galeria de fotos.
¿Alguien me puede ayudar? Lo he intentado yo con la funcion unlink() pero no lo he conseguido.

Muchas Gracias por vuestra ayuda.

Última edición por yazo; 27/02/2004 a las 07:20
  #2 (permalink)  
Antiguo 27/02/2004, 06:27
O_O
 
Fecha de Ingreso: enero-2002
Ubicación: Santiago - Chile
Mensajes: 34.417
Antigüedad: 22 años, 3 meses
Puntos: 129
Pues la función para borrar archivos es unlink() .. ahora si no te "funciona" será por algo .. así que mejor será que pongas los mensajes de error que te arroja tu aplicación y el código que usas .. ademas de indicar "donde" está ese directorio temporal (bajo tu estructura de directorios de tu sitio? o fuera ? ...). Tampoco estaría de más indicar si usas windows o Linux.

En resumen .. cuantos más datos aportes sobre las condiciones del problema .. mejor.

Un saludo,
__________________
Por motivos personales ya no puedo estar con Uds. Fue grato haber compartido todos estos años. Igualmente los seguiré leyendo.
  #3 (permalink)  
Antiguo 27/02/2004, 07:19
 
Fecha de Ingreso: abril-2003
Mensajes: 363
Antigüedad: 21 años
Puntos: 3
Sobre el script

El programa es un album de fotos, le podeis ver en http://www.lamolinadeubierna.com/album.php Este programa crea automaticamente las miniaturas de las imagenes del album de fotos.



<?
/*
* PHOTODIR
* photodir.php - Main program
* Version 1.1, 20-Jan-04
* Copyright 2004 Ross W. Poulton
* [email protected]
* http://www.rossp.org/
*
* This file is part of PhotoDir.
*
* PhotoDir is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* PhotoDir is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with PhotoDir; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
*/
// Define some basic variables:

/* Directory where photos are stored */
$photo_dir = "/usr/local/psa/home/vhosts/lamolinadeubierna.com/httpdocs/album";

/* Directory for cached thumbnails */
$cache_dir = "/usr/local/psa/home/vhosts/lamolinadeubierna.com/httpdocs/album-cache";

/* URI to where photos are stored */
$photo_url = "/album";

/* 'Frame' picture - thumbnails will be centred on top of this image */
$frame_pic = "marco.jpg";

/* 'Folder' picture */
$folder_pic = "carpeta.jpg";

/* 'Parent' picture */
$parent_pic = "anterior.jpg";

/* Maximum dimensions for a thumbnail will be $thumb_max * $thumb_max. Thumbs
are made proportionatly, eg a 200x100 image with thumb_max of 100 will be
resized to 100x50. */
$thumb_max = 100;

/* *********************************************** */
/* END CONFIGURATION */
/* *********************************************** */

if ($_GET['photofile']) {
/* If we're just displaying a photo, send it out to the user. */

$photo = $photo_dir . "/" . stripslashes($_GET['photofile']);

if (realpath($photo) != $photo) {
/* Use realpath to find out if someone has tried spoofing us with
../../../../etc/passwd or similar. */
exit;
}

header("Content-type: image/jpeg");
readfile($photo);
exit;

} elseif ($_GET['thumbfile']) {

/* Display a thumbnail. This will be a resized version of the full file,
but superimposed on your outline image. */

$photo = $photo_dir . "/" . stripslashes($_GET['thumbfile']);
if (realpath($photo) != $photo) {
exit;
}
header("Content-type: image/jpeg");

$md5sum = md5("$photo");
$cache_file = $cache_dir . "/$md5sum";

if ((!file_exists($cache_file)) ||
(filemtime($cache_file) < filemtime($photo))) {

$outline_img = imagecreatefromjpeg($photo_dir . "/" . $frame_pic);
$outline_width = imagesx($outline_img);
$outline_height = imagesy($outline_img);

$src_img = imagecreatefromjpeg($photo);

$size = getimagesize($photo);
$origw = $size[0];
$origh = $size[1];

if ($origw > $origh) {
$neww = $thumb_max;
$diff = $origw / $neww;
$newh = $origh / $diff;
} else {
$newh = $thumb_max;
$diff = $origh / $newh;
$neww = $origw / $diff;
}

$dst_img = imagecreatetruecolor($neww, $newh);

if (function_exists('imagecopyresampled')) {
imagecopyresampled($dst_img,$src_img,0,0,0,0,$neww ,$newh,
$origw,$origh);
} else {
imagecopyresized($dst_img, $src_img,0,0,0,0,$neww,$newh,$origw,
$origh);
}

imagealphablending($outline_img, true);

/* The following block makes up our co-ordinates for placing the
thumbnail on the frame. We always start at least 2 pixels from
each edge, and from there the image is centered both horizontally
and vertically. */

if ($neww > $newh) {
$startx = 2;
$starty = ((100 - $newh) / 2) + 2;
} else {
$startx = ((100 - $neww) / 2) + 2;
$starty = 2;
}

imagecopy($outline_img, $dst_img, $startx, $starty, 0, 0, $neww, $newh);

imagejpeg($outline_img, $cache_file);
}

readfile ($cache_file);

exit;
}

include "header.php";

/* $dir is the full filesystem directory that we're looking at, eg
/var/httpd/photos/Holidays/NewYork2003
$path is everything AFTER the 'standard' photo directory, eg
Holidays/NewYork2003 */

if ($_GET['dir'] != "") {
$dir = $photo_dir . "/" . stripslashes($_GET['dir']);
$path = $_GET['dir'];
} else {
$dir = $photo_dir;
$path = "";
}

if (substr($dir, -1, 1) == "/") {
/* Remove the trailing slash if there is one */
$dir = substr($dir, 0, -1);
}

if (substr($path, -1, 1) == "/") {
/* Remove the trailing slash if there is one */
$path = substr($path, 0, -1);
}

if ($dir != realpath($dir)) {
/* Quick check to make sure our path hasn't been
poisened, eg ../../../../etc/passwd or similar. */
exit;
}

/* Initialise basic variables */
$i = 1;
$first = "y";

if ((is_dir($dir)) && ($dir != "") && ($_GET['image'] == "")) {
if ($dh = opendir($dir)) {
echo "<table border=0 width=100%>";

echo "<tr>";

while (($file = readdir($dh)) !== false) {
if (($file != ".") && ($file != "..") &&
!(($file == $folder_pic) && ($path != "/")) &&
!(($file == $parent_pic) && ($path != "/")) &&
!(($file == $frame_pic) && ($path != "/"))) {

if (($first == "y") && ($path != "")) {
/* If this is the first entry to be displayed on this
page, then put in a 'Parent' link to back up a
level. */
$first = "n";
$parts = explode("/", $path);

if (count($parts) == 0) {
$parent = "";
} else {
for ($j=0; $j<count($parts)-1; $j++) {
$parent .= $parts[$j] . "/";
}
}

echo "<td width=25% align=center valign=top>";
echo "<a href='$PHP_SELF?dir=$parent'>";
echo "<img src='$photo_url/" . $parent_pic . "'>";
echo "<br>Directoria Anterior";
echo "</a><br>";
echo "</td>\n";
}

if (filetype($dir . "/" . $file) == "dir") {
/* This is a directory, display our folder icon */
echo "<td width=25% align=center valign=top>";

echo "<a href='$PHP_SELF?dir=";
if ($path == "") {
echo $file;
} else {
echo $path . "/" . $file;
}
echo "'>";
echo "<img src='$photo_url/" . $folder_pic;
echo "'><br>$file</a><br>";

echo "</td>\n";

$i++;

} elseif (eregi("jpg", $file)) {
/* This is an image, display its thumbnail and a link
to the full image. */
echo "<td width=25% align=center valign=top>";

echo "<a href='$PHP_SELF?image=$path/$file'>";
echo "<img src='$PHP_SELF?thumbfile=";
echo $path . "/" . $file;
echo "'><br>";
echo eregi_replace(".jpg", "", $file) . "</a><br>";

echo "</td>\n";

$i++;

}


if ($i == 4) {
echo "</tr>\n<tr>\n";
$i = 0;
}
}
}
closedir($dh);
echo "</tr></table>";
} else {
echo "Ese directorio no puede ser abierto! :(<br>";
echo "Comprueba los permisos.<br>";
}
} else {
/* Display large photo and information */

echo "<h2 align=center>";
echo eregi_replace(".jpg", "", basename($photo_dir . $_GET['image']));
echo "</h2>";

echo "<p align=center>";

echo "<img src='$PHP_SELF?photofile=" . stripslashes($_GET['image']) . "'>";
echo "<br>";

$size = getimagesize($photo_dir . "/" . $_GET['image']);
$origw = $size[0];
$origh = $size[1];

echo "<b>Tamaño de la Foto</b>: $origw x $origh pixels<br>";

echo "<b>Tamaño del archivo</b>: ";
echo format_file_size(filesize($photo_dir . "/" . $_GET['image']));
echo "<br>";

echo "<b>Ultima Modificación</b>: ";
echo date("d-m-y", filemtime($photo_dir . "/" . $_GET['image']));
echo "<br>";

$parts = explode("/", stripslashes($_GET['image']));
if (count($parts) == 0) {
$parent = "";
} else {
for ($j=0; $j<count($parts)-1; $j++) {
$parent .= $parts[$j] . "/";
}
$parent = substr($parent, 0, -1);
}
echo "<br>";
echo "<a href='$PHP_SELF?dir=$parent'>Volver</a>";
echo "</p>";
}

include "footer.php";

function format_file_size($size) {
if ($size <= 1024) {
return $size . "Mb";
} elseif (($size > 1024) && ($size <= 1024000)) {
$size = $size / 1024;
$size = round($size, 2);
return $size . "Kb";
} elseif (($size > 1024000) && ($size <= 1024000000)) {
$size = $size / 1024000;
$size = round($size, 2);
return $size . "Mb";
} else {
$size = $size / 1024000000;
$size = round($size, 2);
return $size . "Gb";
}
}

?>


Las imagenes del album de fotos estan en la carpeta /album
y las miniaturas estan en /album-cache

Espero vuestras respuestas

Muchas Gracias
Atención: Estás leyendo un tema que no tiene actividad desde hace más de 6 MESES, te recomendamos abrir un Nuevo tema en lugar de responder al actual.
Respuesta




La zona horaria es GMT -6. Ahora son las 13:44.