Me descargue una galeria ya hecha en php para subir mis fotos.
Hay un index en la carpeta /Upload que es para subir la imagen, que copia la imagen con el nombre temporal en plan "298f20b8a1704e7e9cf56e0d46171cbc.JPG"
El código del upload por si hace falta es:
Código PHP:
<?php
include('config.php');
?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title><?php print $title; ?> - Image Hosting Website</title>
<link rel="stylesheet" type="text/css" media="screen" title="<?php print $title; ?> Cascading Stylesheet" href="style.css" />
<script type="text/javascript">
//<![CDATA[
window.onload = function() {
if(window.location.hash) {
document.getElementById('showimg').src = '<?php print $filedir; ?>/' + window.location.hash.substring(1);
document.getElementById('showdiv').style.display = 'block';
}
}
//]]>
</script>
</head>
<body>
<h1 align="center"><?php print $title; ?> - - Sube tus fotos </h1>
<h5 align="center">Sube las imagenes que quieras de una en una, cuando hallas terminado, pincha en el enlace de abajo para volver.</h5>
<p align="center"><span class="Estilo1">Los archivos soportados son: <strong>png, jpg, jpeg, gif y bmp</strong>.</span></p>
</div>
<div id="showdiv"<?php if(empty($imgurl)) { ?> style="display: none;"<?php } ?>>
<img id="showimg" src="<?php if(!empty($imgurl)) print $imgurl; else { ?>about:blank<?php } ?>" alt="Loading image..." />
</div>
<?php
if($_SERVER['REQUEST_METHOD'] == 'POST') {
preg_match('/\.([a-zA-Z]+?)$/', $_FILES['file']['name'], $matches);
if(in_array(strtolower($matches[1]), $accepted)) {
if($_FILES['file']['size'] <= $maxsize) {
$newname = md5_file($_FILES['file']['tmp_name']).'.'.$matches[1];
move_uploaded_file($_FILES['file']['tmp_name'], $filedir.'/'.$newname);
$linkurl = 'http://'.$_SERVER['HTTP_HOST'].preg_replace('/\/([^\/]+?)$/', '/', $_SERVER['PHP_SELF']).'#'.$newname;
$imgurl = 'http://'.$_SERVER['HTTP_HOST'].preg_replace('/\/([^\/]+?)$/', '/', $_SERVER['PHP_SELF']).$filedir.'/'.$newname;
print '<h2>Se ha subido con exito.</h2>';
} else
print '<p>Sorry, that file is too big.</p>';
} else
print '<p>Sorry, that file type is not supported.</p>';
}
?>
<form enctype="multipart/form-data" action="<?php print preg_replace('/\/([^\/]+?)$/', '/', $_SERVER['PHP_SELF']) ?>" method="post">
<input type="hidden" name="MAX_FILE_SIZE" value="<?php print (ini_get('upload_max_filesize')>$maxsize)?ini_get('upload_max_filesize'):$maxsize; ?>" />
<label for="file">Subir la Imagen : </label>
<input type="file" name="file" id="file" />
(Que no ocupe mas de <?php print ((ini_get('upload_max_filesize')>$maxsize)?ini_get('upload_max_filesize'):$maxsize)/1024; ?> KiB)<br />
<input name="submit" type="submit" value="Subiendo" />
</form>
<p id="footer"> <a href="../index.php">Volver a la Galeria De Pedo </a></p>
</body>
</html>
Todo funciona bien, menos por el echo de que las fotos aparecen desordenadas, lo he mirado y no se como las ordena, no las ordena ni por nombre, ni tipo, ni tamaño, ni por fecha.
El código de Galleybuilder.php es:
Código PHP:
<?php
if($_GET["a"] != "")
{
$a = $_GET["a"] . "/";
}
else
{
$a = $default . "/";
}
// This is a very basic way of determining whether to insert
// an extra trailing slash or not
function createGallery($gF, $tF, $tW, $tH, $nR, $nW)
{
echo " <tr>\n";
buildThumbs($gF, $tF, $tW, $tH);
// call to another function to generate the thumbs
$open = opendir($gF);
// open the directory to the gallery folder
$i = 1;
$j = 1;
// we use $i and $j to loop alternating table cells and the number of cells
// per row
while(FALSE !== ($fileName = readdir($open)))
{
$info = pathinfo($gF . $fileName);
// get info for the filename
if(strtolower($info["extension"]) == "jpe" || strtolower($info["extension"]) == "jpeg" || strtolower($info["extension"]) == "jpg" || strtolower($info["extension"]) == "gif" || strtolower($info["extension"]) == "png")
{
// this case-insensitively checks for all possible JPEG, GIF, and PNG extensions and only
// returns files that meet these conditions
echo " <td width=\"" . $tW . "\" height=\"" . $tH . "\" class=\"galleryCell";
if($i == 1)
{
// if $i is 1
echo "1";
$i = 2;
}
else
{
echo "2";
$i = 1;
}
echo "\"><a";
if($nW == TRUE)
{
echo " target=\"_blank\"";
}
echo " href=\"" . $gF . $fileName . "\" title=\"" . $fileName . "\"><img class=\"galleryImage\" src=\"" . $tF . $fileName . "\" border=\"0\"></a></td>\n";
if($j == $nR)
{
// if $j is the number or cells per row...
echo " </tr>\n <tr>\n";
$j = 1;
}
else
{
$j++;
}
}
}
closedir($open);
// close the directory
echo " </tr>\n";
}
function buildThumbs($gF, $tF, $tW, $tH)
{
$open = opendir($gF);
// open the directory to the gallery folder
while(FALSE !== ($fileName = readdir($open)))
{
// loop throught the entire directory
if(!file_exists($tF . $fileName))
{
$info = pathinfo($gF . $fileName);
// get file info for each file
if(strtolower($info["extension"]) == "jpe" || strtolower($info["extension"]) == "jpeg" || strtolower($info["extension"]) == "jpg" || strtolower($info["extension"]) == "gif" || strtolower($info["extension"]) == "png")
{
if(strtolower($info["extension"]) == "jpe" || strtolower($info["extension"]) == "jpeg" || strtolower($info["extension"]) == "jpg")
{
// this narrows it down--the image must be a JPEG
$thumbnail = imagecreatefromjpeg($gF . $fileName);
}
if(strtolower($info["extension"]) == "gif")
{
// it must be a GIF
$thumbnail = imagecreatefromgif($gF . $fileName);
}
if(strtolower($info["extension"]) == "png")
{
// create a PNG
$thumbnail = imagecreatefrompng($gF . $fileName);
}
$oWidth = imagesx($thumbnail);
// original width
$oHeight = imagesy($thumbnail);
// original height
$tWidth = $tW;
// the new thumbnail will have the specified width
$tHeight = floor($oHeight * ($tWidth / $oWidth));
// calculate the thumbnail height by multiplying the original height by the width ratio
if($tHeight > $tH)
{
// if the image is still too tall...
$tHeight = $tH;
// set the height to the max height
$tWidth = floor($oWidth * ($tHeight / $oHeight));
// calculate the thumnail width by multiplying the original width by the height ratio
}
$tempImage = imagecreatetruecolor($tWidth, $tHeight);
// create a temporary image (it's blank right now)
imagecopyresized($tempImage, $thumbnail, 0, 0, 0, 0, $tWidth, $tHeight, $oWidth, $oHeight);
// copy and resize the full-size image into a thumbnail - see PHP.net's imagecopyresized() function for details
if(strtolower($info["extension"]) == "jpe" || strtolower($info["extension"]) == "jpeg" || strtolower($info["extension"]) == "jpg")
{
// save a JPG thumbnail!
$thumbnail = imagejpeg($tempImage, $tF . $fileName);
}
if(strtolower($info["extension"]) == "gif")
{
// save a GIF thumbnail!
$thumbnail = imagegif($tempImage, $tF . $fileName);
}
if(strtolower($info["extension"]) == "png")
{
// save a PNG thumbnail!
$thumbnail = imagepng($tempImage, $tF . $fileName);
}
}
}
}
closedir($open);
// close the directory
}
function listAlbums($gF, $aS, $dF)
{
// $gF is the path to the folder that contains the subfolders
// example: "gallery/"
// $aS is the separator between each album title
// example: " • "
// $dF is the default folder that we wish to exclude from the list
// example: "default_gallery"
$open = opendir($gF);
// open the directory to the gallery folder
$i = 1;
$toReturn = "";
// we use $i to loop through the count and $toReturn to come
// up with a full album list to echo later
while(FALSE !== ($fileName = readdir($open)))
{
if(is_dir($gF . $fileName) && $fileName != "." && $fileName != ".." && $fileName != $dF)
{
// if the file is actually a directory... ("." and ".." are not directories) and NOT the default
$displayName = str_replace("_", " ", $fileName);
// change all underscores to spaces in the display name
$displayName = ucwords($displayName);
// capitalize the first letter of each word in the display name
$toReturn = $toReturn . "<a href=\"?a=" . $fileName . "\">" . $displayName . "</a>" . $aS;
// add the album name, and add a separator
}
}
$aS_length = strlen($aS);
// here we figure out how many characters $aS is
$aS_length = $aS_length * -1;
// get the negative number
echo substr_replace($toReturn, "", $aS_length);
// this is a messy but understandable way to remove the last
// album separator from the list
}
?>
O es en el index de la galería donde tengo que poner el orden?
La tabla de la galeria lleva esto:
Código PHP:
<table align="center">
<?php createGallery("Upload/pics/" . $a, "Upload/pics/" . $a . "thumbs/", 120, 80, 5, FALSE); ?>
</table
Saludos