php/flash image upload + thumbnail generation
Posted: Mon Apr 14, 2003 11:55 am
Hi,
I been looking for a tutorial online for this but haven't been able to find what I'm after, so I'm hoping a more experienced php coder might be able give me some pointers.
I'm currently developing a flash site, which I need to have lots of dynamic features. One of these is a gallery page. I'm ok with the flash (actionscript) side of things, but I'm a little stumped on the php side.
My initial thoughts are:
client uploads image to server via web. php then saves the original image in a folder called 'main' and a duplicate image, re-sized to 75x75 (or whatever) pixels in a folder called 'thumbs'. Then, I can call a simple php script which reads the directory structure, passes that data (probably as an array) into flash and flash loads the images in sequentially. Once all the thumbnails are loaded, it then calls the same simple php script which reads the directory structure for the folder 'main' and on reciept of that data, flash preceeds to load in the first image.
This bits working fine...
code:
------------------------------------------------------------------------
// read directory script... called using "read_directory.php?dir=thumbs" etc
<?php
if($dir == 'thumbs'){
if ($thumbs = opendir('./thumbs/')) {
while (false !== ($file = readdir($thumbs))) {
if ($file != "." && $file != "..") {
echo "$file\n";
}
}
closedir($thumbs);
}
}
else if ($dir == 'main')
if ($main = opendir('./main/')) {
while (false !== ($file = readdir($main))) {
if ($file != "." && $file != "..") {
echo "$file\n";
}
}
closedir($main);
}
?>
------------------------------------------------------------------------
Should I seperate the functions of the script, so that there's a script for uploading and a seperate script that generates all the thumbnails once the client has finished uploading (just by clicking a button on the upload page?)
Only the client will be able to add pictures (and thinking about it, should be able to remove them as well
) so I don't think there's any need to generate thumbnails everytime the page is called so I'd rather go the 'semi-dynamic' route.
Does this seem like a viable solution to my requirements, or is there a better way ??
Thanks in advance,
Jon
I been looking for a tutorial online for this but haven't been able to find what I'm after, so I'm hoping a more experienced php coder might be able give me some pointers.
I'm currently developing a flash site, which I need to have lots of dynamic features. One of these is a gallery page. I'm ok with the flash (actionscript) side of things, but I'm a little stumped on the php side.
My initial thoughts are:
client uploads image to server via web. php then saves the original image in a folder called 'main' and a duplicate image, re-sized to 75x75 (or whatever) pixels in a folder called 'thumbs'. Then, I can call a simple php script which reads the directory structure, passes that data (probably as an array) into flash and flash loads the images in sequentially. Once all the thumbnails are loaded, it then calls the same simple php script which reads the directory structure for the folder 'main' and on reciept of that data, flash preceeds to load in the first image.
This bits working fine...
code:
------------------------------------------------------------------------
// read directory script... called using "read_directory.php?dir=thumbs" etc
<?php
if($dir == 'thumbs'){
if ($thumbs = opendir('./thumbs/')) {
while (false !== ($file = readdir($thumbs))) {
if ($file != "." && $file != "..") {
echo "$file\n";
}
}
closedir($thumbs);
}
}
else if ($dir == 'main')
if ($main = opendir('./main/')) {
while (false !== ($file = readdir($main))) {
if ($file != "." && $file != "..") {
echo "$file\n";
}
}
closedir($main);
}
?>
------------------------------------------------------------------------
Should I seperate the functions of the script, so that there's a script for uploading and a seperate script that generates all the thumbnails once the client has finished uploading (just by clicking a button on the upload page?)
Only the client will be able to add pictures (and thinking about it, should be able to remove them as well
Does this seem like a viable solution to my requirements, or is there a better way ??
Thanks in advance,
Jon