Autor Zpráva
Silver8000
Profil
Cau lidi mam takovej mensi problem a ten se tyka pole array.
Pri nacitani slozky mi to hlasi chybu : Array to string conversion in C:\xampp\htdocs\index.php on line 74
Mohli by jste mi prosim poradit jak tuto chybu odstranit aniz bych musel pouzit error_reporting(0);
Zde je kod :

<?php
$scan_dir = scandir('.');
$disallowed_objects = array('.','..','index.php','.htaccess', '.htpasswd');
$objects = array_diff($scan_dir,$disallowed_objects);
$web_allowed_ext = array('','htm','html','xml','css','js','php','txt');
foreach($objects as $object){

$get_dots = explode('.',$object);
$file = str_replace('.'.end($get_dots),'',$object);

if(filetype($object)=='dir'){
     $extension = '';
}else{
     $extension = strtolower(end($get_dots));
}
if(in_array($extension,$web_allowed_ext)){
    $filetype = filetype($object);
     $filesize = filesize($object);
     $permissions = decoct(fileperms($object)%01000);

$stat = stat($object);
date_default_timezone_set('Europe/London');
$created = strftime("%H:%M:%S(%d.%m.%Y)\n", $stat['ctime']);

$modified = strftime("%H:%M:%S(%d.%m.%Y)\n", $stat['mtime']);

$objects_details[] = (object) array(
                         "file_type"    => $filetype,
                         "file_name"    => $file,
                         "file_size"    => $filesize,
                         "file_permissions" => $permissions,
                         "file_created"=> $created,
                         "file_modified"=> $modified,
                         "file_extension"   => $extension,
                       );

}
 
}

function sort_objects($a, $b)
{
if(@$_GET['sort_by']){
$sort_by = @$_GET['sort_by'];
    return strcmp($a->$sort_by,$b->$sort_by);
}else{
    return strcmp($a->file_type,$b->file_type);
    return strcmp($a->file_name,$b->file_name);
}


}
    usort($objects_details,'sort_objects');
for($obj=0;$obj<count($objects_details);$obj++){
//print_r($objects_details[$obj]);
$file_type = $objects_details[$obj]->file_type;
$file_name = $objects_details[$obj]->file_name;
$file_size = $objects_details[$obj]->file_size;
$file_permisions = $objects_details[$obj]->file_permissions;
$file_created = $objects_details[$obj]->file_created;
$file_modified = $objects_details[$obj]->file_modified;
$file_extension = $objects_details[$obj]->file_extension;
$objects .= <<<OBJECTS
    <tr>
      <td>$file_type</td>
      <td>$file_name</td>
      <td>$file_size</td>
      <td>$file_permisions</td>
      <td>$file_created</td>
      <td>$file_modified</td>
      <td>$file_extension</td>
    </tr>
OBJECTS;
}
$index =<<<INDEX
<div align="center">
<a href="./">Sort by File type</a>
<a href="?sort_by=file_name">Sort by File name</a>
<a href="?sort_by=file_size">Sort by File size</a>
<a href="?sort_by=file_permissions">Sort by File permissions</a>
<a href="?sort_by=file_created">Sort by File created time</a>
<a href="?sort_by=file_modified">Sort by File last modified</a>
<a href="?sort_by=file_extension">Sort by File extension</a>
<table style="text-align: left;" border="1"
 cellpadding="0" cellspacing="0">
<tbody>
    <tr>
      <td>File type</td>
      <td>File name</td>
      <td>File size</td>
      <td>File permission</td>
      <td>File created time</td>
      <td>File last modified</td>
      <td>File extension</td>
    </tr>
$objects
</tbody>
</table></div>
INDEX;
echo $index;
?>
Diky moc za pomoc predem.
Tori
Profil
Silver8000:
Který řádek je u vás 74? Tady to je ř.63: $objects .= <<<OBJECTS - na ř.4 vytváříte pole tohoto názvu, ta proměnná stále existuje. Buď použijte proměnnou jiného (lepšího) názvu, anebo před ř.54 nastavte $objects na prázdný řetězec.
Silver8000
Profil
ja uz jsem na to prisel pred radek s funkci for jsem nahoru musel dat jeste $objects = ''; a tim se to vyresilo.
Kazdopadne dik za radu.

Vaše odpověď

Mohlo by se hodit


Prosím používejte diakritiku a interpunkci.

Ochrana proti spamu. Napište prosím číslo dvě-sta čtyřicet-sedm: