Jump to content

[Resolvido] Erro de listagem de ficheiros


Recommended Posts

Posted (edited)

boas tenho um script para fazer a listagem de ficheiros de acordo com a pasta pedida

	echo'<div class="intcol_2">
			<h2>'.icon('img/prod.png').'Listagem de Documentos
				<span>
					<a href="javascript:void(0)">Data: </a>'.date('Y-m-d').'
				</span>
			</h2>';

echo '<table>';
th('Ficheiro,tamanho,criado,modificado');
$pasta = opendir($pasta);
while($file = readdir($pasta)){
	if($file !='.' && $file !='..')
  echo '<tr>
		<td><a href="'.$pasta.'/'.$file.'">'.ucfirst($file).'</a></td>
		<td>'.round((filesize($file) / 1024), 2).' Kb</td>
		<td>'.date('d-m-Y',filectime($file)).'</td>
		<td>'.date('d-m-Y',filemtime($file)).'</td>
		</tr>';
}
echo'</table>';

Mas está a funcionar com erros, e apenas me lista o 2º ficheiro todos os outros dão este erro.

Warning: filesize(): stat failed for calc.php in C:\SERVER\htdocs\Man\admin\admin_func.php on line 24

Warning: filectime(): stat failed for calc.php in C:\SERVER\htdocs\Man\admin\admin_func.php on line 25

Outra coisa que reparei foi o link do ficheiro aparecer assim

endereço_raiz/man/Resource id #10/calc.php

Edited by N3lson

You can't do it, kid. But don't worry, my boy. You're not the only one. No one else can do it.

Posted (edited)

Aviso

Esta função pode retornar o booleano FALSE, mas também pode retornar um valor não-booleano que pode ser avaliado como FALSE, como 0 ou "". Leia a seção em Booleanos para maiores informações. Utilize o operador === para testar o valor retornado por esta função

/* Esta é a forma correta de varrer o diretório */
while (false !== ($file = readdir($handle))) {
	echo "$file\n";
}
/* Esta é a forma INCORRETA de varrer o diretório */
while ($file = readdir($handle)) {
	echo "$file\n";
}

~in http://pt2.php.net/readdir

anyway, isso nao sao erros, sao avisos, mas acho q isto te vai resolver:

http://stackoverflow.com/a/6388742/1869192

repara no @

Edited by I-NOZex
  • Vote 1

B2R » Beat2Revolution v3.0b | Regista e divulga-nos

beat2revolution.net
Posted

Sim já tinha reparado no @ mas isto é o k esta acontecer

lista os documentos todos mas apenas me dá os dados de 1

e4u1.jpg

You can't do it, kid. But don't worry, my boy. You're not the only one. No one else can do it.

Posted
while(($file = readdir($pasta)) !== false) {
 if($file !='.' && $file !='..') {
    $filepath = $pasta.'/'.$file;
    echo '<tr>
            <td><a href="'.$filepath.'">'.ucfirst($file).'</a></td>
            <td>'.round((filesize($filepath) / 1024), 2).' Kb</td>
            <td>'.date('d-m-Y',filectime($filepath)).'</td>
            <td>'.date('d-m-Y',filemtime($filepath)).'</td>
          </tr>';
 }
}
  • Vote 1
IRC : sim, é algo que ainda existe >> #p@p
Posted

Obrigado ao 2 pela ajuda, já rola com as instruções do HappyHippyHippo.

O problema era ter de indicar o caminho para cada linha do loop?

Pensava que como iria buscar o ficheiro não era necessário.

You can't do it, kid. But don't worry, my boy. You're not the only one. No one else can do it.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...

Important Information

By using this site you accept our Terms of Use and Privacy Policy. We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.