Oinam Forum
You are not logged in.
This discussion is an extension of the article, Flash 8 File Upload Download. You can view the working demo on oinam labs.
Feel free to ask questions and give us feedbacks as we will be able to reply your querries much better here than the comments on the blog.
Thanks
Offline
This upload feature was also used along with PHP in 23hq new photo upload feature.
Offline
Hi there,
I'm a PHP user, and you solution is really great.
But I'm not familiar with ColdFusion and I don't know what type of variable (or type of string) the flash needs to set up the list of downloadable images.
Can you give me hints on the please ?
Thanks, bye.
Atruskor
Offline
Hi,
The following code should help you settle the issue if you are using PHP for the file uploaddownload in Flash.
<?
// create a unique identifier based on the current time in microseconds
$uniqid = uniqid();
// get the File Name which is going to upload from previous page
$fileName = basename( $_FILES['Filedata']['name'] );
// set the path of the upload directory and appened the uniqid to the actual file as prefix , so file name can't be same and overlapped
$uploadFile = "userUploads/".$uniqid.$fileName;
// upload the selected file to the predefined path from temp
move_uploaded_file( $_FILES['Filedata']['tmp_name'] , $uploadFile );
?>
Offline
I downloaded the source. I use dreamweaver and I try to test source files but i keep getting error 405. can anyone please help me. I have iis installed on my computer and try to test but keep getting that error. sorry for bad english.
Offline
mo too!i keep getting error 405.please help me!!!
Offline
The errors which are related to the webserver are something which we cannot help with. They are not related to the souce code or the sample that we put up there.
For more details on error 405, please refer to this article, HTTP Error 405 - Method not allowed.
Offline
Hi,
First. My english is basic. (sorry). but one Big intencion in help us.
I don¬Ąt use ColdFusion, i like PHP. i get in the internet the following sources (uploadFile.php and viewFiles.php)
I get too, the source/demo. When i have tested, is showed the error 405.
Solution is basic: Configure the index.html
flashObj.addVariable ("uploadUrl", "uploadFile.php");
flashObj.addVariable ("downloadListUrl", "viewFiles.php");
Source uploadFile.php:
$dir = 'userUploads';
$uploadfile = "$dir/" . basename( $_FILES['Filedata']['name'] );
if ( move_uploaded_file( $_FILES['Filedata']['tmp_name'] , $uploadfile ) ) {
$uploadfile = "$dir/" . basename( $_FILES['Filedata']['name'] );
echo( '1 a ' . $_FILES['Filedata']['name']);
}else {
echo( '0');
}
source viewFiles.php:
<?php
header("Expires: mon, 06 jan 1990 00:00:01 gmt");
header("Pragma: no-cache");
header("Cache-Control: no-store, no-cache, must-revalidate");
?><files>
<?php
$imageFolder = 'userUploads/';
if ($handle = opendir($imageFolder)) {
$echo = "";
/* This is the correct way to loop over the directory. */
while (false !== ($file = readdir($handle))) {
$echo .= ($file!="." && $file!="..") ? "\t".'<f name="'.$file.'" size="'.filesize($imageFolder.$file).'" path="'.$imageFolder.$file.'" />'."\n" : "";
}
echo $echo;
closedir($handle);
}
?>
</files>
Regards
Leo Moraes
Last edited by leomoraes (2006-03-18 08:49:59)
Offline
Can the UploadURL parameter take a URI with variables? E.g. Http://www.somewhere.com/upload.php?var … le2=qwerty
Like:
<!--
var flashObj = new FlashObject ("includes/uploadDownload.swf", "uploadDownload", "550", "400", 8, "#FFFFFF", true);
flashObj.addVariable ("uploadUrl", "http://www.somewhere.com/clients/?PHPSESSID=c67a1126b7536e56ff9c6d913b3d46e1&method=collections&jid=189");
flashObj.addVariable ("downloadListUrl", "http://www.somewhere.com/clients/includes/listDir.php");
flashObj.addVariable ("maxFileSize", "50000"); // in kb
flashObj.write ("flashcontent");
// -->
Any help appreciated!
Offline
FIXED:
To pass URL parameters through the UploadDownload tool, just create more flashObj.addVariable() entries, then append them to the uploadURL in the Uploadownload.as file. This will overcome the behaviour of flash whereby it coverts the query string variables to flash variables. E.g:
<!--
var flashObj = new FlashObject ("includes/uploadDownload.swf", "uploadDownload", "550", "400", 8, "#FFFFFF", true);
flashObj.addVariable ("downloadListUrl", "<?=$sitename?>clients/includes/listDir.php");
flashObj.addVariable ("PHPSessID", "<? echo session_id(); ?>");
flashObj.addVariable ("JID", "<?=$attributes["jid"]?>");
flashObj.addVariable ("maxFileSize", "50000"); // in kb
flashObj.write ("flashcontent");
// -->
Not, uploadURL is NOT defined.
IN uploadDownload.as, find:
// to be provided via flashvars
if (uploadUrl == null)
{
SessionID = PHPSessID;
JobID = JID;
uploadUrl = "http://www.yoursite.com/clients/?PHPSESSID="+SessionID+"&method=saveImages&jid="+JobID;
};
Hope this helps, I'm probably not making this clear, but thought I'd offer what I learned.
Offline
What I really want to do is implement this as part of a J2EE solution using Java and Servlets. Also, I want to make sure this is secure. Are there any issues there? Thanks everyone!
Slim
Offline
Anyone know of a way to use ASP as the upload script ?
Got it working with PHP and CFM, but I need to use ASP.
Thanks guys!!
Offline
Hi,
I have downloaded the source and placed in on the web,
I made the folder "userUploads" writeable for apache
I don't get any error's bud uploaden dosn't work.
Do i forget something ?
Is there an readme file somewhere ?
Please help me with this one.
Offline
Me too. Uploaded the bin folder, made userUploads writable, upload seems to work - but no files are uploaded.
Offline
This really is helpful, but does anyone have an ASP.NET 2.0 version of the code in VB? Thanks!
Offline
I'm attempting to add a "Cancel" button to interupt uploads. I'm no Flash guru, and I'm having difficulties. Brajeshwar, are you able to implement a cancel feature, or advise me on where to start?
Many thanks for an excellent tool!
Offline
I would still love to know why nothing works for me. I went through all the necessary steps, but no files get uploaded.
Offline
> I'm attempting to add a "Cancel" button to interupt uploads.
There is a fileReference.cancel method in the flash player to cancel ongoing upload/download operation.
Usage is simple, myFileReference.cancel () typically triggered with the cancel button in your code.
Offline
Hey Gavin, could you supply an example of content in your listDir.php file so we can see how its all associated. I need to be able to send a variable at login that dictates the fileUploads folder location or name. Seems like you have that above. PS- new to the forum, thanks.
Brajeshwar, it's really great, thanks.
Offline
Hi Chris, sorry for the tardy reply, for some reason I didn't get an alert from this forum.
This code spits out a formated XML file for the flash utility. Hope it helps.
My listDir.php is:
<?
function dirList ($directory)
{
// create an array to hold directory list
$results = array();
// create a handler for the directory
$handler = opendir($directory);
// keep going until all files in directory have been read
while ($file = readdir($handler)) {
// if $file isn't this directory or its parent,
// add it to the results array
if ($file != '.' && $file != '..')
$results[] = $file;
}
// tidy up: close the handler
closedir($handler);
// done!
return $results;
}
$list = dirList("/path/to/image/folder");
?>
<files>
<?
rsort($list);
while ($i = array_pop($list)){
?>
<f name="<?= $i?>" size="<?= filesize("/path/to/image/folder".$i)?>" path="" />
<?
}
?>
</files>
Offline