Subir archivos.
Código PHP:
Ver original<?
/*
Directory Listing Script - Version 2
====================================
*/
$startdir = '.';
$showthumbnails = true;
$showdirs = true;
$forcedownloads = false;
'dlf',
'index.php',
'Thumbs',
'.htaccess',
'.htpasswd'
);
$displayindex = false;
/*
Allow uploads? - If enabled users will be able to upload
files to any viewable directory.
*/
$allowuploads = true;
$overwrite = false;
'index.html',
'index.htm',
'default.htm',
'default.html'
);
'png' => 'jpg.gif',
'jpeg' => 'jpg.gif',
'bmp' => 'jpg.gif',
'jpg' => 'jpg.gif',
'gif' => 'gif.gif',
'zip' => 'archive.png',
'rar' => 'archive.png',
'pdf' => 'pdf.gif',
'rar' => 'rar.gif',
);
/*
Only edit what is below this line if you are sure that you know what you
are doing!
*/
$leadon = $startdir;
if($leadon=='.') $leadon = '';
if((substr($leadon, -1, 1)!='/') && $leadon!='') $leadon = $leadon . '/'; $startdir = $leadon;
if($_GET['dir']) {
//check this is okay.
if(substr($_GET['dir'], -1, 1)!='/') { $_GET['dir'] = $_GET['dir'] . '/';
}
$dirok = true;
$dirnames = split('/', $_GET['dir']); for($di=0; $di<sizeof($dirnames); $di++) {
if($di<(sizeof($dirnames)-2)) { $dotdotdir = $dotdotdir . $dirnames[$di] . '/';
}
if($dirnames[$di] == '..') {
$dirok = false;
}
}
if(substr($_GET['dir'], 0, 1)=='/') { $dirok = false;
}
if($dirok) {
$leadon = $leadon . $_GET['dir'];
}
}
if($_GET['download'] && $forcedownloads) {
header("Content-type: application/x-download"); header('Content-Disposition: attachment; filename="'.$file.'"'); }
}
if($allowuploads && $_FILES['file']) {
$upload = true;
if(!$overwrite) {
$upload = false;
}
}
if($upload) {
}
}
$opendir = $leadon;
if(!$leadon) $opendir = '.';
$opendir = '.';
$leadon = $startdir;
}
while (false !== ($file = readdir($handle))) { //first see if this file is required in the listing
if ($file == "." || $file == "..") continue;
$discard = false;
for($hi=0;$hi<sizeof($hide);$hi++) { if(strpos($file, $hide[$hi])!==false) { $discard = true;
}
}
if($discard) continue;
if (@filetype($leadon.$file) == "dir") { if(!$showdirs) continue;
$n++;
if($_GET['sort']=="date") {
}
else {
$key = $n;
}
$dirs[$key] = $file . "/";
}
else {
$n++;
if($_GET['sort']=="date") {
}
elseif($_GET['sort']=="size") {
$key = @filesize($leadon.$file) . ".$n"; }
else {
$key = $n;
}
$files[$key] = $file;
if($displayindex) {
}
}
}
}
}
//sort our files
if($_GET['sort']=="date") {
@ksort($dirs, SORT_NUMERIC
); @ksort($files, SORT_NUMERIC
); }
elseif($_GET['sort']=="size") {
@ksort($files, SORT_NUMERIC
); }
else {
}
//order correctly
if($_GET['order']=="desc" && $_GET['sort']!="size") {$dirs = @array_reverse($dirs);}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Directory Listing of
<?=dirname($_SERVER['PHP_SELF']).'/'.$leadon;?></title>
<link rel="stylesheet" type="text/css" href="dlf/styles.css" />
<?
if($showthumbnails) {
?>
<script language="javascript" type="text/javascript">
<!--
function o(n, i) {
document.images['thumb'+n].src = 'dlf/i.php?f='+i;
}
function f(n) {
document.images['thumb'+n].src = 'dlf/trans.gif';
}
//-->
</script>
<?
}
?>
</head>
<body>
<div id="container">
<div id="logo"><img src="" alt="logo" width="800" height="150" longdesc="logotipo de la empresa" /></div>
<h1>Directory Listing of
<?=dirname($_SERVER['PHP_SELF']).'/'.$leadon;?></h1>
<div id="breadcrumbs"> <a href="<?=$_SERVER['PHP_SELF'];?>">Principal [Home]</a>
<?
$breadcrumbs = split('/', $leadon); if(($bsize = sizeof($breadcrumbs))>0) { $sofar = '';
for($bi=0;$bi<($bsize-1);$bi++) {
$sofar = $sofar . $breadcrumbs[$bi] . '/';
echo ' > <a href="'.$_SERVER['PHP_SELF'].'?dir='.urlencode($sofar).'">'.$breadcrumbs[$bi].'</a>'; }
}
$baseurl = $_SERVER['PHP_SELF'] . '?dir='.$_GET['dir'] . '&';
$fileurl = 'sort=name&order=asc';
$sizeurl = 'sort=size&order=asc';
$dateurl = 'sort=date&order=asc';
switch ($_GET['sort']) {
case 'name':
if($_GET['order']=='asc') $fileurl = 'sort=name&order=desc';
break;
case 'size':
if($_GET['order']=='asc') $sizeurl = 'sort=size&order=desc';
break;
case 'date':
if($_GET['order']=='asc') $dateurl = 'sort=date&order=desc';
break;
default:
$fileurl = 'sort=name&order=desc';
break;
}
?>
</div>
<div id="listingcontainer">
<div id="listingheader">
<div id="headerfile"><a href="<?=$baseurl . $fileurl;?>">Archivo [File]</a></div>
<div id="headersize"><a href="<?=$baseurl . $sizeurl;?>">Tamaño</a></div>
<div id="headermodified"><a href="<?=$baseurl . $dateurl;?>">Última actualización [Last update]</a></div>
</div>
<div id="listing">
<?
$class = 'b';
if($dirok) {
?>
<div><a href="
<?=$_SERVER['PHP_SELF'].'?dir='.urlencode($dotdotdir);?>" class="
<?=$class;?>"><img src="dlf/dirup.png" alt="Folder" /><strong>..</strong> <em>-</em>
<?=date ("M d Y h:i:s A", filemtime($dotdotdir));?></a></div>
<?
if($class=='b') $class='w';
else $class = 'b';
}
for($i=0;$i<$arsize;$i++) {
?>
<div><a href="
<?=$_SERVER['PHP_SELF'].'?dir='.urlencode($leadon.$dirs[$i]);?>" class="
<?=$class;?>"><img src="dlf/folder.png" alt="
<?=$dirs[$i];?>" /><strong>
<?=$dirs[$i];?></strong> <em>-</em>
<?=date ("M d Y h:i:s A", filemtime($leadon.$dirs[$i]));?></a></div>
<?
if($class=='b') $class='w';
else $class = 'b';
}
for($i=0;$i<$arsize;$i++) {
$icon = 'unknown.png';
$supportedimages = array('gif', 'png', 'jpeg', 'jpg'); $thumb = '';
if($showthumbnails && in_array($ext, $supportedimages)) { $thumb = '<span><img src="dlf/trans.gif" alt="'.$files[$i].'" name="thumb'.$i.'" /></span>';
$thumb2 = ' onmouseover="o('.$i.', \''.urlencode($leadon . $files[$i]).'\');" onmouseout="f('.$i.');"';
}
if($filetypes[$ext]) {
$icon = $filetypes[$ext];
}
$filename = $files[$i];
$filename = substr($files[$i], 0, 40) . '...'; }
$fileurl = $leadon . $files[$i];
if($forcedownloads) {
$fileurl = $_SESSION['PHP_SELF'] . '?dir=' . urlencode($leadon) . '&download=' . urlencode($files[$i]); }
?>
<div><a href="
<?=$fileurl;?>" class="
<?=$class;?>"
<?=$thumb2;?>><img src="dlf/
<?=$icon;?>" alt="
<?=$files[$i];?>" /><strong>
<?=$filename;?></strong> <em>
<?=round(filesize($leadon.$files[$i])/1024);?>KB</em>
<?=date ("M d Y h:i:s A", filemtime($leadon.$files[$i]));?><?=$thumb;?></a></div>
<?
if($class=='b') $class='w';
else $class = 'b';
}
?></div>
<?
if($allowuploads) {
$phpallowuploads = (bool
) ini_get('file_uploads'); $phpmaxsize = ini_get('upload_max_filesize'); $phpmaxsize = trim($phpmaxsize); switch($last) {
case 'g':
$phpmaxsize *= 1024;
case 'm':
$phpmaxsize *= 1024;
}
?>
<div id="upload">
<div id="uploadtitle"><strong>File Upload</strong> (Max Filesize: <?=$phpmaxsize;?>KB)</div>
<div id="uploadcontent">
<?
if($phpallowuploads) {
?>
<form method="post" action="
<?=$_SERVER['PHP_SELF'];?>?dir=
<?=urlencode($leadon);?>" enctype="multipart/form-data">
<input type="file" name="file" /> <input type="submit" value="Upload" />
</form>
<?
}
else {
?>
File uploads are disabled in your php.ini file. Please enable them.
<?
}
?>
</div>
</div>
<?
}
?>
</div>
</div>
</body>
</html>
Me va muy bien pero hay un problema. Está permitido [$allowuploads = true;]
No me permite subir un archivo de 8 Mb. He leído en algún sitio que no se permite más de un porcentaje de la capacidad del servidor. Cuando lo cargo este script me pone "Max Filesize: 20480KB"
Saludos.
Caminantejm.