Monday, March 29, 2010

Want to display files from a directory,...

Heya,

So I am using a really basic PHP script that uploads files
(particularly mp3s and images) into a generic folder called
''files''. I'm trying to figure out a way to display these files
(simply links for the mp3s and ideally thumbnails for the images)
via a simply html or php page. I'm looking for any advice you all
may have?Want to display files from a directory,...
This may not be possible, but ask your hosting company
whether

they can set your ''files folder'' ONLY to permit folder
browsing.





''withhisstripes'' %26lt;webforumsuser@macromedia.com%26gt; wrote
in message

news:euen9m$qh1$1@forums.macromedia.com...

%26gt; Heya,

%26gt; So I am using a really basic PHP script that uploads
files

%26gt; (particularly

%26gt; mp3s and images) into a generic folder called ''files''.
I'm trying to

%26gt; figure out

%26gt; a way to display these files (simply links for the mp3s
and ideally

%26gt; thumbnails

%26gt; for the images) via a simply html or php page. I'm
looking for any advice

%26gt; you

%26gt; all may have?

%26gt;





Want to display files from a directory,...
Hi



as long your remote server supports e.g. PHP, it麓s of
course possible to do just that -- the code attached is a complete
page which you will have to copy%26amp;paste in a blank Dreamweaver
document and ''save as...'' in your ''files'' directory. Must be saved
as PHP file !



Please note: it doesn麓t provide a thumbnail
functionality
(was too lazy doing that now ;-)), but it will display the
following file types : .jpg, . gif,. mp3, that is, all other file
types possibly residing in this directory are getting ignored.



All displayed files also provide links, which are opened in a
new target=_blank window -- that should work for image files and
also mp3麓s. Some extras included here are: additional display
of the file creation date plus the file size. I also added some PHP
comments in between to help you understand what麓s going on



Hope this helps ;-)
On Wed, 28 Mar 2007 21:39:02 +0000 (UTC), ''withhisstripes''

%26lt;webforumsuser@macromedia.com%26gt; wrote:



%26gt; So I am using a really basic PHP script that uploads
files (particularly

%26gt;mp3s and images) into a generic folder called ''files''.
I'm trying to figure out

%26gt;a way to display these files (simply links for the mp3s
and ideally thumbnails

%26gt;for the images) via a simply html or php page. I'm
looking for any advice you

%26gt;all may have?



Can't do it with just html, but the following might be
helpful:



%26lt;!DOCTYPE HTML PUBLIC ''-//W3C//DTD HTML 4.01//EN''

''
http://www.w3.org/TR/html4/strict.dtd''%26gt;

%26lt;html%26gt;

%26lt;head%26gt;

%26lt;meta http-equiv=''Content-Type'' content=''text/html;
charset=iso-8859-1''%26gt;

%26lt;title%26gt;File List%26lt;/title%26gt;

%26lt;meta http-equiv=''imagetoolbar'' content=''no''%26gt;

%26lt;style type=''text/css''%26gt;

ul,li{

list-style: none;

margin: 0;

padding: 0;

}

%26lt;/style%26gt;

%26lt;/head%26gt;

%26lt;body%26gt;

%26lt;?php

// Root relative path to the directory

// Change this if the files directory is not at the site's
root

$dir='/files';



$d=opendir($_SERVER['DOCUMENT_ROOT'].'/files')

or die('Failed to open directory');

$link=''\t%26lt;li%26gt;%26lt;a
href=\''%s/%s\''%26gt;%s%26lt;/a%26gt;%26lt;/li%26gt;\n'';

$img=''\t%26lt;li%26gt;%26lt;a href=\''%s/%s\''%26gt;''.

''%26lt;img src=\''thumb.php?img=%s\'' border=\''0\''
alt=\''\''%26gt;%26lt;/a%26gt;%26lt;/li%26gt;\n'';

print ''%26lt;ul%26gt;\n'';

while(($f=readdir($d))!==false) {

if(preg_match('/mp3/i',$f)){

printf($link,$dir,$f,$f);

}elseif(preg_match('/jpg$|jpeg$|gif$|png$/',$f)){

printf($img,$dir,$f,''$dir/$f'');

}

}

print ''%26lt;/ul%26gt;\n'';

?%26gt;

%26lt;/body%26gt;

%26lt;/html%26gt;



The above requires the following (which requires PHP's GD
library) to be

saved as thumb.php in the same directory as the above page:



%26lt;?php

// Max width and height for the thumbnails. Adjust as desired

$thumbWidth = 100;

$thumbHeight = 80;



$img=$_GET['img'];

if(!$img){

exit;

}

$fullimage=$_SERVER['DOCUMENT_ROOT'].''/''.$_GET['img'];



if(!file_exists($fullimage))

exit;

// Get image dimensions and type

if($size=getimagesize($fullimage)){

$width_orig=$size[0];

$height_orig=$size[1];

$type=$size[2];

$mime=$size['mime'];

switch($type){

case 1:

$image=imagecreatefromgif($fullimage);

break;

case 2:

$image=imagecreatefromjpeg($fullimage);

break;

case 3:

$image=imagecreatefrompng($fullimage);

break;

default:

exit($type);

}

if (!$image) { /* if it failed */

// create a 100*30 image

$im=imagecreate($thumbWidth, $thumbHeight);

// white background and blue text

$bg = imagecolorallocate($im, 255, 0, 0);

$textcolor = imagecolorallocate($im, 0, 0, 255);

// write the string at the top left

imagestring($im, 5, 20, 20, ''Failed'', $textcolor);

// output the image

header(''Content-type: image/jpeg'');

imagejpeg($im);

exit;

}

$factor = min($thumbWidth/$width_orig,
$thumbHeight/$height_orig);

$newWidth=round($width_orig * $factor);

$newHeight=round($height_orig * $factor);



// Resample

$image_p = imagecreatetruecolor($newWidth, $newHeight)

or exit;



imagecopyresampled($image_p, $image, 0, 0, 0, 0,

$newWidth, $newHeight, $width_orig, $height_orig);



// Output

header(''Content-type: $mime'');

imagejpeg($image_p);

}

?%26gt;



Gary


Ken thanks for the suggestion I didn't know you could do it
that way!



Geschenk thank you that works beautifully.



Gary, can you tell me what I'm doing wrong:
http://photos.cathedralworldoutreach.org/files/index2.php



I labeled the first snippet index2.php and labeled the second
snippet thumb.php because index2.php calls for a thumb.php file in
the code, which I assume was the second snippet. I guess I'm a
little confused. Thanks my friend!
On Sun, 1 Apr 2007 23:18:11 +0000 (UTC), ''withhisstripes''

%26lt;webforumsuser@macromedia.com%26gt; wrote:



%26gt; Gary, can you tell me what I'm doing wrong:

%26gt;
http://photos.cathedralworldoutreach.org/files/index2.php





Not sure. Here is a working example:


http://testing.apptools.com/experiments/files/



Try creating a file with *only* the following in the source
code:



%26lt;?php

phpinfo()

?%26gt;



Save it with a .php extension, upload it, then view it in a
browser. See

if you have GD support.



Gary


It says ''No Input Specified''...?
On Tue, 3 Apr 2007 00:39:47 +0000 (UTC), ''withhisstripes''

%26lt;webforumsuser@macromedia.com%26gt; wrote:



%26gt;It says ''No Input Specified''...?





Then you mistyped the file name portion of the url.



Gary

No comments:

Post a Comment