Jump to content

Uploading complete... now for the next issue


rnb_cassanova

Recommended Posts

 

i have a target folder where the users uploads defaults to but now i want to be able to see whats in that folder, but only that folder, so in essence the best way i can describe is something like this...

http://esupport.epson-europe.com/ProductHome.aspx?lng=en-GB&data=dkmEK02SU002FeroarA05EEv55UIF0kgE0cfqxevtXS8ndgU003D&tc=6#7

 

all of the files in one place, constantly updated and the user can download.

 

I hope im making sense,

 

Cheers

 

David

Link to comment
Share on other sites

You would need to loop through the directory and create links.

<?php
$dir = "path/to/dir";
if ($handle = opendir($dir)) {

  /* This is the correct way to loop over the directory. */

  while (false !== ($file = readdir($handle))) {
    if($file != ".." && $file != "."){
    echo '<a href="'.$dir.$file.'" target="_blank" border=0>'.$file.'</a><br />';
    }
  }
}
?>

 

This will just create links.

 

Ray

?>

 

 

Link to comment
Share on other sites

Hi, im currently getting the following error

 

Warning: opendir(/Uploads) [function.opendir]: failed to open dir: No error in C:\wamp\www\DV8 System\TargetUploadsPage.php on line 3

 

I have changed the target directory, but am leaving something out. the file is within the root and called \uploads

 

Cheers lads

 

david

Link to comment
Share on other sites

the directory either has to be linked from where the script is being run from or use the absolute path

 

$dir = "C:/wamp/www/uploads/";

 

or if I am reading correctly

 

$dir = "../uploads/";

 

the .. at the beginning will make the script go back one directory to the root then open the uploads directory

 

i know I forgot it in my last post but don't forget to add the slash in the link

echo '<a href="'.$dir."/".$file.'" target="_blank" border=0>'.$file.'</a><br />';

 

Ray

Link to comment
Share on other sites

the one you sent me the -

 

<?php
$dir = "C:/wamp/www/DV8 System/uploads";
if ($handle = opendir($dir)) {

  /* This is the correct way to loop over the directory. */

  while (false !== ($file = readdir($handle))) {
    if($file != ".." && $file != "."){
   echo '<a href="'.$dir."/".$file.'" target="_blank" border=0>'.$file.'';
    }
  }
}
?>

Link to comment
Share on other sites

ok when I posted it I forgot to use the code tags so the end got cut off. Also changed it to use double quotes so you can put the line break at the end

 

echo "<a href=\"".$dir."/".$file."\" target=\"_blank\" border=0>$file</a><br>\n";

 

Ray

Link to comment
Share on other sites

rmb,

 

Also here is the simple code I use to do the same thing...

 

<?php

$dn = opendir (wowadd);

$exclude = array("index.php", ".", "..", "download.php", "download.html", "download.php");

 

// adiciona os arquivos ao array $arquivos

while($fn = readdir($dn)) {

if ($fn == $exclude[0] || $fn == $exclude[1] || $fn == $exclude[2] || $fn == $exclude[3] || $fn == $exclude[4] || $fn == $exclude[5]) continue;

$arquivos[] = $fn;

}

// ordena o vetor

sort($arquivos);

// exibe os arquivos

 

foreach ($arquivos as $arquivo)

 

if (is_dir($arquivo)){

$dir .= "<img src='/wow.png'> <a href='$arquivo'>$arquivo</a><br>";

}else{

$tamanho = filesize($arquivo);

$m = 'bytes';

if ($tamanho>1024) {

$tamanho=round($tamanho/1024,2);

$m = 'KB';

} elseif($tamanho > 1024*1024){

$tamanho = round(($tamanho/1024)/1024,2);

$m = 'MB';

}

$arq .= "<img src='../wow.png'> <a href='$arquivo'>$arquivo</a> - $tamanho $m<br>";

}

echo $dir . $arq;

 

closedir($dn);

?>

 

currently it is set to the directory WOWADD which is in the same root folder as the calling script. Now if you figure out a way to have variable passed to this to change directories based on selection in the submiting form please let me know...

 

drop me a note at thezaphod04 AT gmail  DOT  com and we can comlaborate some..

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

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.