Error en upload de ficheros

YoMismo
16 de Diciembre del 2003
El problema es que si subo ficheros de imágenes, .docs o pdfs mediante PHP me inserta algo (no sé qué es, pero los ficheros doblan su tamaño) y se vuelven ilegibles (las imágenes se cortan por la mitad y los pdf y docs ni se pueden abrir). Los ficheros de texto plano (.txt, .htm...) suben perfectamente.

He probado con funciones copy y ftp de PHP y nada pero si los subo con un cliente de FTP tradicional no hay problemas.

Me imagino que será algo de la configuración de PHP, pero no encuentro un caso como el mío en ningún sitio. Ya estoy más que desesperado

Estoy usando Red Hat 8, Apache 2.0 y PHP 4.2.2.

Muchas gracias de antemano

rargueso
16 de Diciembre del 2003
Como subes los ficheros? La configuracion afecta al tamaño maximo del fichero o a si se pueden subir ficheros o no. Nunca afecta al contenido. Si pones un ejemplo de como lo haces te podremos ayudar. De todas formas por ahi deje un post indicando como lo hago yo:

http://www.programacion.com/foros/7/msg/62931/

Un saludo

YoMismo
16 de Diciembre del 2003
Pues no sé si te querrás leer todo el código, yo describía el problema para facilitar... porque es parte de un gestor de contenidos llamado Claroline. Ellos dicen que funciona. Pero a mi sólo en parte.

No sé si será del código... El caso es que he probado con pequeños scripts hechos por mi con la función copy y ftp_connect ftp_login y ftp_put y los resultados siempre han sido los mismos.

En fin, que ahí va el código.

Gracias por lo de tu script, pero ya lo había revisado y no me había sacado de dudas.

Por cierto, esto sí que es rapidez, que se agradece muchísimo!

<?php // $Id: document.php,v 1.63 2003/06/23 14:19:31 peeters Exp $
/*
+----------------------------------------------------------------------+
| CLAROLINE version 1.3.2 $Revision: 1.63 $ |
+----------------------------------------------------------------------+
| Copyright (c) 2001, 2002 Universite catholique de Louvain (UCL) |
+----------------------------------------------------------------------+
| This source file is subject to the GENERAL PUBLIC LICENSE, |
| available through the world-wide-web at |
| http://www.gnu.org/copyleft/gpl.html |
+----------------------------------------------------------------------+
| Authors: Thomas Depraetere <[email protected]> |
| Hugues Peeters <[email protected]> |
| Christophe Gesch?<[email protected]> |
+----------------------------------------------------------------------+

DESCRIPTION:
****
This PHP script allow user to manage files and directories on a remote http server.
The user can : - navigate trough files and directories.
- upload a file
- rename, delete, copy a file or a directory

The script is organised in four sections.

* 1st section execute the command called by the user
Note: somme commands of this section is organised in two step.
The script lines always begin by the second step,
so it allows to return more easily to the first step.

* 2nd section define the directory to display

* 3rd section read files and directories from the directory defined in part 2

* 4th section display all of that on a HTML page
*/

/*======================================
CLAROLINE MAIN
======================================*/
$langFile = "document";
include('../include/claro_init_global.inc.php');

$htmlHeadXtra[] =
"<style type=text/css>
<!--
.comment { margin-left: 30px}
.invisible {color: #999999}
.invisible a {color: #999999}
-->
</style>";

$htmlHeadXtra[] =
"<script>
function confirmation (name)
{
if (confirm(" $langAreYouSureToDelete "+ name + " ?"))
{return true;}
else
{return false;}
}
</script>";

$nameTools = $langDoc;

$QUERY_STRING=''; // used forthe breadcrumb
// when one need to add a parameter after the filename

include('../include/claro_init_header.inc.php');

/*
* Library for the file display
*/

include("../include/fileDisplayLib.inc.php");

/*
* Lib for event log, stats & tracking
* plus record of the access
*/

@include('../include/libs/events.lib.inc.php');
event_access_tool($nameTools);

if (! $is_courseAllowed) die ("<center>Not allowed !</center>");

$is_AllowedToEdit = $is_courseAdmin;

if($is_AllowedToEdit) // for teacher only
{
include ("../include/fileManageLib.inc.php");
include ("../include/fileUploadLib.inc.php");

if ($uncompress == 1)
include("../include/pclzip/pclzip.lib.php");
}

/*======================================
FILEMANAGER BASIC VARIABLES DEFINITION
======================================*/

$dbTable = $_course['dbNameGlu']."document";
$baseServDir = $rootSys;
$baseServUrl = $urlAppend."/";
$courseDir = $_course['path']."/document";
$baseWorkDir = $baseServDir.$courseDir;

// $baseWorkDir = $baseServDir.$urlAppend.$courseDir;

$maxFilledSpace = 100000000;

/*======================================
CLAROLINE MAIN SETTINGS PART 2
======================================*/


// clean information submited by the user from antislash

stripSubmitValue($HTTP_POST_VARS);
stripSubmitValue($HTTP_GET_VARS);



/*============================================================================*/

if($is_AllowedToEdit) // TEACHER ONLY
{

/* > > > > > > MAIN SECTION < < < < < < <*/


/*======================================
UPLOAD FILE
======================================*/


/*
* check the request method in place of a variable from POST
* because if the file size exceed the maximum file upload
* size set in php.ini, all variables from POST are cleared !
*/

if ($REQUEST_METHOD == 'POST' && !$submitImage && !$cancelSubmitImage)
{
/*
* Check if the file is valide (not to big and exists)
*/

if(!is_uploaded_file($userFile))
{
$dialogBox .= $langFileError.'<br>'.$langNotice.' : '.$langMaxFileSize.' '.get_cfg_var('upload_max_filesize');
}

/*
* Check the file size doesn't exceed
* the maximum file size authorized in the directory
*/

elseif ( ! enough_size($HTTP_POST_FILES['userFile']['size'], $baseWorkDir, $maxFilledSpace))
{
$dialogBox .= $langNoSpace;
}

/*
* Unzipping stage
*/

elseif ($uncompress == 1 && preg_match("/.zip$/", $HTTP_POST_FILES['userFile']['name']) )
{
$zipFile = new pclZip($userFile);
$is_allowedToUnzip = true ; // default initialisation

// Check the zip content (real size and file extension)

$zipContentArray = $zipFile->listContent();

foreach($zipContentArray as $thisContent)
{
if ( preg_match("~.(php.*|phtml)$~", $thisContent['filename']) )
{
$dialogBox .= $langZipNoPhp;
$is_allowedToUnzip = false;
break;
}

$realFileSize += $thisContent['size'];
}


if ( ($realFileSize + $alreadyFilledSpace) > $maxFilledSpace) // check the real size.
{
$dialogBox .= $langNoSpace;
$is_allowedToUnzip = false;
}

if ($is_allowedToUnzip)
{ /*
* Uncompressing phase
*/

if (PHP_OS == "Linux" && ! get_cfg_var("safe_mode"))
{
// Shell Method - if this is possible, it gains some speed

exec("unzip -d "".$baseWorkDir.$uploadPath."/"".$fileName." "
.$HTTP_POST_FILES['userFile']['tmp_name']);
}
else
{
// PHP method - slower...

chdir($baseWorkDir.$uploadPath);
$unzippingSate = $zipFile->extract();
}

$dialogBox .= $langDownloadAndZipEnd;
}
}
else // if $uncompress
{
$fileName = trim ($HTTP_POST_FILES['userFile']['name']);

/* CHECK FOR NO DESIRED CHARACTERS */
$fileName = replace_dangerous_char($fileName);
//$fileName = str_replace(" ", "_", $fileName);

/* TRY TO ADD AN EXTENSION TO FILES WITOUT EXTENSION */
$fileName = add_ext_on_mime($fileName);

/* HANDLE PHP FILES */
$fileName = php2phps($fileName);

/* COPY THE FILE TO THE DESIRED DESTINATION */
copy ($userFile, $baseWorkDir.$uploadPath."/".$fileName);

$dialogBox .= $langDownloadEnd;

} // end else


/*
* In case of HTML file, looks for image needing to be uploaded too
*/

if (strrchr($fileName, ".") == ".htm" || strrchr($fileName, ".") == ".html")
{
$fp = fopen($baseWorkDir.$uploadPath."/".$fileName, "r");

// search and store occurences of the <IMG> tag in an array

$buffer = fread ($fp, filesize ($baseWorkDir.$uploadPath."/".$fileName));

if ( preg_match_all("~<[:space:]*img[^>]*>~i",
$buffer, $matches) )
{
$imgTagList = $matches[0];
}

fclose ($fp); unset($buffer);

// Search the image file path from all the <IMG> tag detected

if (sizeof($imgTagList) > 0)
{
$imgFilePath=array();

foreach($imgTagList as $thisImgTag)
{
if ( preg_match("~src[:space:]*=[:space:]*["]{1}([^"]+)["]{1}~i",
$thisImgTag, $matches) )
{
$imgFilePath[] = $matches[1];
}
}

$imgFilePath = array_unique($imgFilePath); // remove duplicate entries
}

/*
* Generate Form for image upload
*/

if ( sizeof($imgFilePath) > 0)
{
$dialogBox .= "<br><b>$langMissingImagesDetected</b><br>n"
."<form method="post" action="$PHP_SELF""
."enctype="multipart/form-data">n"
."<input type="hidden" name="relatedFile""
."value="".$uploadPath."/".$fileName."">n"
."<table border="0">n";

foreach($imgFilePath as $thisImgFilePath )
{
$dialogBox .= "<tr>n"
."<td>".basename($thisImgFilePath)." : </td>n"
."<td>"
."<input type="file" name="imgFile[]">"
."<input type="hidden" name="imgFilePath[]" "
."value="".$thisImgFilePath."">"
."</td>n"
."</tr>n";
}

$dialogBox .= "</table>n"

."<div align="right">"
."<input type="submit" name="cancelSubmitImage" value="".$langCancel."">n"
."<input type="submit" name="submitImage" value="".$langOk.""><br>"
."</div>n"
."</form>n";
} // end if ($imgFileNb > 0)
} // end if (strrchr($fileName) == "htm"
} // end if is_uploaded_file


/*======================================
UPLOAD RELATED IMAGE FILES
======================================*/

if ($submitImage)
{
$uploadImgFileNb = sizeof($imgFile);

if ($uploadImgFileNb > 0)
{
// Try to create a directory to store the image files

$imgDirectory = $relatedFile."_files";

while (file_exists($baseWorkDir.$imgDirectory))
{
$nb += 1;
$imgDirectory = $relatedFile."_files".$nb;
}

mkdir($baseWorkDir.$imgDirectory, 0777);

$mkInvisibl = $imgDirectory;

// move the uploaded image files into the corresponding image directory

for ($i=0; $i < $uploadImgFileNb; $i++)
{
if (is_uploaded_file($imgFile[$i]))
{
move_uploaded_file($imgFile[$i], $baseWorkDir.$imgDirectory."/".$imgFile_name[$i]);
}
}


/*
* Open the old html file and replace the src path into the img tag
*/

$fp = fopen($baseWorkDir.$relatedFile, "r");

while ( !feof($fp) )
{
$buffer = fgets($fp, 4096);

for ($i=0; $i<$uploadImgFileNb ; $i++)
{
$buffer = str_replace( $HTTP_POST_VARS['imgFilePath'][$i],
"./".basename($imgDirectory)."/".$imgFile_name[$i],
$buffer);
}

$newHtmlFileContent .= $buffer;
}

fclose ($fp);

/*
* Write the resulted new file
*/

$fp = fopen($baseWorkDir.$relatedFile, "w");
fwrite($fp, $newHtmlFileContent);
} // end if ($uploadImgFileNb > 0)
} // end if ($submitImage)





/*======================================
MOVE FILE OR DIRECTORY
======================================*/

/*
* The code begin with STEP 2
* so it allows to return to STEP 1 if STEP 2 unsucceeds
*/

/*-------------------------------------
MOVE FILE OR DIRECTORY : STEP 2
--------------------------------------*/

if (isset($moveTo))
{
if ( move($baseWorkDir.$source,$baseWorkDir.$moveTo) )
{
update_db_info("update", $source, $moveTo."/".basename($source));
$dialogBox = $langDirMv;
}
else
{
$dialogBox = $langImpossible;

/* return to step 1 */
$move = $source;
unset ($moveTo);
}

}


/*-------------------------------------
MOVE FILE OR DIRECTORY : STEP 1
--------------------------------------*/

if (isset($move))
{
$dialogBox .= form_dir_list("source", $move, "moveTo", $baseWorkDir);
}



/*======================================
DELETE FILE OR DIRECTORY
======================================*/


if ( isset($delete) )
{
if ( my_delete($baseWorkDir.$delete))
{
update_db_info("delete", $delete);
$dialogBox = $langDocDeleted;
}
}




/*=========================================
RENAME
=========================================*/

/*
* The code begin with STEP 2
* so it allows to return to STEP 1
* if STEP 2 unsucceds
*/


/*-------------------------------------
RENAME : STEP 2
--------------------------------------*/

if (isset($renameTo))
{
if ( my_rename($baseWorkDir.$sourceFile, $renameTo) )
{
update_db_info("update", $sourceFile, dirname($sourceFile)."/".$renameTo);
$dialogBox = $langElRen;
}
else
{
$dialogBox = $langFileExists;

/* return to step 1 */
$rename = $sourceFile;
unset($sourceFile);
}
}


/*-------------------------------------
RENAME : STEP 1
--------------------------------------*/

if (isset($rename))
{
$fileName = basename($rename);
$dialogBox .= "<!-- rename -->n"
."<form>n"
."<input type="hidden" name="sourceFile" value="".$rename."">n"
.$langRename." ".htmlentities($fileName)." ".$langIn." :n"
."<input type="text" name="renameTo" value="".$fileName."">n"
."<input type="submit" value="".$langOk."">n"
."</form>n";
}




/*======================================
CREATE DIRECTORY
======================================*/

/*
* The code begin with STEP 2
* so it allows to return to STEP 1
* if STEP 2 unsucceds
*/

/*-------------------------------------
STEP 2
--------------------------------------*/
if (isset($newDirPath) && isset($newDirName))
{
$newDirName = replace_dangerous_char(trim($newDirName));

if(check_name_exist($baseWorkDir.$newDirPath."/".$newDirName) )
{
$dialogBox = $langFileExists;
$createDir = $newDirPath; unset($newDirPath);// return to step 1
}
else
{
mkdir($baseWorkDir.$newDirPath."/".$newDirName, 0700);
$dialogBox = $langDirCr;
}
}


/*-------------------------------------
STEP 1
--------------------------------------*/

if (isset($createDir))
{
$dialogBox .= "<!-- create dir -->n"
."<form>n"
."<input type="hidden" name="newDirPath" value="$createDir">n"
.$langNameDir." : n"
."<input type="text" name="newDirName">n"
."<input type="submit" value="".$langOk."">n"
."</form>n";
}


/*======================================
ADD/UPDATE/REMOVE COMMENT
======================================*/

/*
* The code begin with STEP 2
* so it allows to return to STEP 1
* if STEP 2 unsucceds
*/

/*--------------------------------------
COMMENT : STEP 2
--------------------------------------*/

if (isset($newComment))
{
$newComment = trim($newComment); // remove spaces

/* Check if there is yet a record for this file in the DB */

$result = mysql_query ("SELECT * FROM `$dbTable` WHERE path="".$commentPath.""");

while($row = mysql_fetch_array($result, MYSQL_ASSOC))
{
$attribute['path' ] = $row['path' ];
$attribute['visibility'] = $row['visibility'];
$attribute['comment' ] = $row['comment' ];
}


/* Determine the correct query to the DB */

if ($attribute['visibility'] == "i")
{
$query = "UPDATE `$dbTable` SET comment="".$newComment."" WHERE path="".$commentPath.""";
}
elseif ($newComment == "" && $attribute['visibility'] != "i")
{
$query = "DELETE FROM `$dbTable` WHERE path="".$commentPath.""";
}
elseif ($attribute['comment'] != "" && $newComment != "")
{
$query= "UPDATE `$dbTable` SET comment="".$newComment."" WHERE path="".$commentPath.""";
}
else
{
$query = "INSERT INTO `$dbTable` SET path="".$commentPath."", comment="".$newComment."", visibility='v'";
}

mysql_query($query);
unset($attribute);

$dialogBox = $langComMod;

//echo "INSERT INTO `$dbTable` SET path="".$commentPath."", comment="".$newComment."", visibility='v'";
}

/*--------------------------------------
COMMENT : STEP 1
--------------------------------------*/

if (isset($comment))
{
/* Search the old comment */
$result = mysql_query ("SELECT comment FROM `$dbTable` WHERE path="".$comment.""");
while($row = mysql_fetch_array($result, MYSQL_ASSOC)) $oldComment = $row['comment'];

$fileName = basename($comment);

$dialogBox .= "<!-- comment -->n"
."<form>n"
."<input type="hidden" name="commentPath" value="".$comment."">n"
.$langAddComment." ".htmlentities($fileName)."n"
."<textarea rows=2 cols=50 name="newComment">".$oldComment."</textarea>n"
."<input type="submit" value="".$langOk."">n"
."</form>n";
}




/*======================================
VISIBILITY COMMANDS
======================================*/

if (isset($mkVisibl) || isset($mkInvisibl))
{
$visibilityPath = $mkVisibl.$mkInvisibl; // At least one of these variables are empty. So it's okay to proceed this way

/* Check if there is yet a record for this file in the DB */
$result = mysql_query ("SELECT * FROM `$dbTable` WHERE path LIKE "".$visibilityPath.""");
while($row = mysql_fetch_array($result, MYSQL_ASSOC))
{
$attribute['path' ] = $row['path' ];
$attribute['visibility'] = $row['visibility'];
$attribute['comment' ] = $row['comment' ];
}

if ($mkVisibl)
{
$newVisibilityStatus = "v";
}
elseif ($mkInvisibl)
{
$newVisibilityStatus = "i";
}

if ($attribute['comment'])
{
$query = "UPDATE `$dbTable` SET visibility='$newVisibilityStatus' WHERE path="".$visibilityPath.""";
}
elseif ($attribute['visibility']=="i" && $newVisibilityStatus == "v")
{
$query="DELETE FROM `$dbTable` WHERE path="".$visibilityPath.""";
}
else
{
$query="INSERT INTO `$dbTable` SET path="".$visibilityPath."", visibility="".$newVisibilityStatus.""";
}

mysql_query($query);
unset($attribute);

$dialogBox = $langViMod;

}
} // END is Allowed to Edit




/*======================================
DEFINE CURRENT DIRECTORY
======================================*/

if (isset($openDir) || isset($moveTo) || isset($createDir) || isset($newDirPath) || isset($uploadPath) ) // $newDirPath is from createDir command (step 2) and $uploadPath from upload command
{
$curDirPath = $openDir . $createDir . $moveTo . $newDirPath . $uploadPath;
/*
* NOTE: Actually, only one of these variables is set.
* By concatenating them, we eschew a long list of "if" statements
*/
}
elseif ( isset($delete) || isset($move) || isset($rename) || isset($sourceFile) || isset($comment) || isset($commentPath) || isset($mkVisibl) || isset($mkInvisibl)) //$sourceFile is from rename command (step 2)
{
$curDirPath = dirname($delete . $move . $rename . $sourceFile . $comment . $commentPath . $mkVisibl . $mkInvisibl);
/*
* NOTE: Actually, only one of these variables is set.
* By concatenating them, we eschew a long list of "if" statements
*/
}
else
{
$curDirPath="";
}

if ($curDirPath == "/" || $curDirPath == "\" || strstr($curDirPath, ".."))
{
$curDirPath =""; // manage the root directory problem

/*
* The strstr($curDirPath, "..") prevent malicious users to go to the root directory
*/
}

$curDirName = basename($curDirPath);
$parentDir = dirname($curDirPath);

if ($parentDir == "/" || $parentDir == "\")
{
$parentDir =""; // manage the root directory problem
}




/*======================================
READ CURRENT DIRECTORY CONTENT
======================================*/

/*--------------------------------------
SEARCHING FILES & DIRECTORIES INFOS
ON THE DB
--------------------------------------*/

/* Search infos in the DB about the current directory the user is in */

$result = mysql_query ("SELECT * FROM `$dbTable` WHERE path LIKE "".$curDirPath."/%" AND path NOT LIKE "".$curDirPath."/%/%"");

while($row = mysql_fetch_array($result, MYSQL_ASSOC))
{
$attribute['path' ][] = $row['path' ];
$attribute['visibility'][] = $row['visibility'];
$attribute['comment' ][] = $row['comment' ];
}


/*--------------------------------------
LOAD FILES AND DIRECTORIES INTO ARRAYS
--------------------------------------*/
@chdir (realpath($baseWorkDir.$curDirPath))
or die("<center>
<b>Wrong directory !</b>
<br> Please contact your platform administrator.</center>");
$handle = opendir(".");

define('A_DIRECTORY', 1);
define('A_FILE', 2);


while ($file = readdir($handle))
{
if ($file == "." || $file == "..")
{
continue; // Skip current and parent directories
}

$fileList['name'][] = $file;

if(is_dir($file))
{
$fileList['type'][] = A_DIRECTORY;
$fileList['size'][] = false;
$fileList['date'][] = false;
}
elseif(is_file($file))
{
$fileList['type'][] = A_FILE;
$fileList['size'][] = filesize($file);
$fileList['date'][] = filectime($file);
}


/*
* Make the correspondance between
* info given by the file system
* and info given by the DB
*/

$keyDir = sizeof($dirNameList)-1;

if ($attribute)
{
$keyAttribute = array_search($curDirPath."/".$file, $attribute['path']);
}

if ($keyAttribute !== false)
{
$fileList['comment' ][] = $attribute['comment' ][$keyAttribute];
$fileList['visibility'][] = $attribute['visibility'][$keyAttribute];
}
else
{
$fileList['comment' ][] = false;
$fileList['visibility'][] = false;
}
} // end while ($file = readdir($handle))

/*
* Sort alphabetically the File list
*/

if ($fileList)
{
array_multisort($fileList['type'], $fileList['name'],
$fileList['size'], $fileList['date'],
$fileList['comment'],$fileList['visibility']);
}




/*----------------------------------------
CHECK BASE INTEGRITY
--------------------------------------*/


if ($attribute)
{
/*
* check if the number of DB records is greater
* than the numbers of files attributes previously given
*/

if (sizeof($attribute['path']) > (sizeof($fileList['comment']) + sizeof($fileList['visibility'])))
{
/* SEARCH DB RECORDS WICH HAVE NOT CORRESPONDANCE ON THE DIRECTORY */
foreach( $attribute['path'] as $chekinFile)
{
if ($dirNameList && in_array(basename($chekinFile), $dirNameList))
continue;
elseif ($fileNameList && in_array(basename($chekinFile), $fileNameList))
continue;
else
$recToDel[]= $chekinFile; // add chekinFile to the list of records to delete
}

/* BUILD THE QUERY TO DELETE DEPRECATED DB RECORDS */
$nbrRecToDel = sizeof ($recToDel);

for ($i=0; $i < $nbrRecToDel ;$i++)
{
$queryClause .= "path LIKE "".$recToDel[$i]."%"";
if ($i < $nbrRecToDel-1) {$queryClause .=" OR ";}
}

mysql_query("DELETE FROM `$dbTable` WHERE ".$queryClause);
mysql_query("DELETE FROM `$dbTable` WHERE comment LIKE '' AND visibility LIKE 'v'");
/* The second query clean the DB 'in case of' empty records (no comment an visibility=v)
These kind of records should'nt be there, but we never know... */
}
} // end if ($attribute)



closedir($handle);
unset($attribute);




/* > > > > > > END: COMMON TO TEACHERS AND STUDENTS < < < < < < <*/



/*==========================
DISPLAY
==========================*/


$dspCurDirName = htmlentities($curDirName);
$cmdCurDirPath = rawurlencode($curDirPath);
$cmdParentDir = rawurlencode($parentDir);

?>
<br>
<div class="fileman" align="center">
<table width="100%" border="0" cellspacing="2" cellpadding="4">
<tr>
<td><h3><?= $langDoc; ?></h3></td>
<td align="right">
<? if($is_AllowedToEdit)
{ ?>
<a href="#" onClick="MyWindow=window.open('../help/help_document.php','MyWindow','toolbar=no,location=no,directories=no,status=yes,menubar=no,scrollbars=yes,resizable=yes,width=350,height=450,left=300,top=10'); return false;">
<?php echo $langHelp ?>
</a>
<? } ?>
</td>
</tr>

<tr>

<?php


if($is_AllowedToEdit)
{
/*--------------------------------------
DIALOG BOX SECTION
--------------------------------------*/

if ($dialogBox)
{
echo "<td bgcolor="#FFCC00">",
"<!-- dialog box -->",
$dialogBox,
"</td>n";
}
else
{
echo "<td>n<!-- dialog box -->n&nbsp;n</td>n";
}

/*--------------------------------------
UPLOAD SECTION
--------------------------------------*/
echo "<!-- upload -->",
"<td align="right">",
"<form action="$PHP_SELF" method="post" enctype="multipart/form-data">",
"<input type="hidden" name="uploadPath" value="$curDirPath">",
$langDownloadFile," : ",
"<input type="file" name="userFile">",
"<input type="submit" value="$langDownload"><br>",
"<input type="checkbox" name="uncompress" value="1">",
$langUncompress,
"</form>",
"</td>n";

}

?>

</tr>
</table>

<table width="100%" border="0" cellspacing="2">

<?php

$is_AllowedToEdit ? $colspan = 8 : $colspan = 3;

/*--------------------------------------
CURRENT DIRECTORY LINE
--------------------------------------*/

echo "<tr>n",
"<td colspan=$colspan>n";


/* GO TO PARENT DIRECTORY */

if ($curDirName) /* if the $curDirName is empty, we're in the root point
and we can't go to a parent dir */
{
echo "<!-- parent dir -->n",
"<a href="$PHP_SELF?openDir=".$cmdParentDir."">n",
"<img src="../img/parent.gif" border=0 align="absbottom" hspace=5>n",
"<small>$langUp</small>n",
"</a>n";
}

if ($is_AllowedToEdit)
{
/* CREATE DIRECTORY */

echo "<!-- create dir -->n",
"<a href="$PHP_SELF?createDir=".$cmdCurDirPath."">",
"<img src="../img/dossier.gif" border=0 align="absbottom" hspace=5>",
"<small> $langCreateDir</small>",
"</a>",

"</tr>n",
"</td>n";
}


/* CURRENT DIRECTORY */

if ($curDirName) /* if the $curDirName is empty, we're in the root point
and there is'nt a dir name to display */
{
echo "<!-- current dir name -->n",
"<tr>n",
"<td colspan="$colspan" align="left" bgcolor="#4171B5">n",
"<img src="../img/opendir.gif" align="absbottom" vspace=2 hspace=5>n",
"<font color="white"><b>".$dspCurDirName."</b></font>n",
"</td>n",
"</tr>n";
}

echo "<tr bgcolor="$color2" align="center" valign="top">";

echo "<td>$langName</td>n",
"<td>$langSize</td>n",
"<td>$langDate</td>n";

if ($is_AllowedToEdit)
{
echo "<td>$langDelete</td>n",
"<td>$langMove</td>n",
"<td>$langRename</td>n",
"<td>$langComment</td>n",
"<td>$langVisible</td>n";
}

echo "</tr>n";


/*--------------------------------------
DISPLAY FILE LIST
--------------------------------------*/

if ($fileList)
{
while (list($fileKey, $fileName) = each ($fileList['name']))
{
$dspFileName = htmlentities($fileName);
$cmdFileName = rawurlencode($curDirPath."/".$fileName);

if ($fileList['visibility'][$fileKey] == "i")
{
if ($is_AllowedToEdit)
{
$style=" class="invisible"";
}
else
{
continue; // skip the display of this file
}
}
else
{
$style="";
}

if ($fileList['type'][$fileKey] == A_FILE)
{
$image = choose_image($fileName);
$size = format_file_size($fileList['size'][$fileKey]);
$date = format_date($fileList['date'][$fileKey]);
$urlFileName = "document_goto.php?doc_url=".urlencode($cmdFileName);
//$urlFileName = "goto/?doc_url=".urlencode($cmdFileName);
//format_url($baseServUrl.$courseDir.$curDirPath."/".$fileName));
}
elseif ($fileList['type'][$fileKey] == A_DIRECTORY)
{
$image = 'dossier.gif';
$size = '';
$date = '';
$urlFileName = $PHP_SELF.'?openDir='.$cmdFileName;
}

echo "<tr align="center"",$style,">n",
"<td align="left">",
"<a href="".$urlFileName.""".$style.">",
"<img src="./../img/",$image,"" border=0 hspace=5>",$dspFileName,"</a>",
"</td>n",

"<td><small>",$size,"</small></td>n",
"<td><small>",$date,"</small></td>n";

/* NB : Before tracking implementation the url above was simply
* "<a href="",$urlFileName,""",$style,">"
*/

if($is_AllowedToEdit)
{
/* DELETE COMMAND */
echo "<td>",
"<a href="",$PHP_SELF,"?delete=",$cmdFileName,"" ",
"onClick="return confirmation('",addslashes($dspFileName),"');">",
"<img src="../img/supprimer.gif" border=0>",
"</a>",
"</td>n";

/* COPY COMMAND */
echo "<td>",
"<a href="",$PHP_SELF,"?move=",$cmdFileName,"">",
"<img src="../img/deplacer.gif" border=0>",
"</a>",
"</td>n";

/* RENAME COMMAND */
echo "<td>",
"<a href="",$PHP_SELF,"?rename=",$cmdFileName,"">",
"<img src="../img/renommer.gif" border=0>",
"</a>",
"</td>n";

/*COMMENT COMMAND */
echo "<td>",
"<a href="",$PHP_SELF,"?comment=",$cmdFileName,"">",
"<img src="../img/comment.gif" border=0>",
"</a>",
"</td>n";

/* VISIBILITY COMMAND */

echo "<td>";

if ($fileList['visibility'][$fileKey] == "i")
{
echo "<a href="",$PHP_SELF,"?mkVisibl=",$cmdFileName,"">",
"<img src="../img/invisible.gif" border=0>",
"</a>";
}
else
{
echo "<a href="",$PHP_SELF,"?mkInvisibl=",$cmdFileName,"">",
"<img src="../img/visible.gif" border=0>",
"</a>";
}

echo "</td>n";
} // end if($is_allowedToEdit)

echo "</tr>n";

/* COMMENTS */

if ($fileList['comment'][$fileKey] != "" )
{
$fileList['comment'][$fileKey] = htmlentities($fileList['comment'][$fileKey]);
$fileList['comment'][$fileKey] = nl2br($fileList['comment'][$fileKey]);

echo "<tr align="left">n",
"<td colspan="$colspan">",
"<div class="comment">",
$fileList['comment'][$fileKey],
"</div>",
"</td>n",
"</tr>n";
}
} // end each ($fileList)
} // end if ( $fileList)

echo "</table>n",
"</div>n";
?>
<br>
<br>
<?php @include($includePath."/claro_init_footer.inc.php"); ?>