Im using the Flash fileReference class with a PHP serverside script to allow users to upload images to my application. It works just fine; the images are being uploaded to the sever and downloaded to Flash without any problems, plus my PHP script makes a time stamped copy in a seperate folder in case another user uploads an image of the same name and overwrites the prevoius one.
The problem is this: if a user uploads and image and then the same user uploads a different image of the same name, the previous image is overwritten (as it should be) but then Flash is loading the first image stil - from the cache - therefore displaying the wrong one to the user...
It only effects some browsers (namely IE) with particular settings (Automatically check for new versions of stored pages in IE) but obviously I need it to work universally. Also, as ive got an XML gallery on the site too, id ideally like to stop Flash from caching completely (if possible).
The fileReference code is:
CODE:
System.security.allowDomain("www.tshirtsetc.co.uk");
import flash.net.FileReference;
// The listener object listens for FileReference events.
var listener:Object = new Object();
listener.onSelect = function(selectedFile:FileReference):Void {
upWin._x = 200;
selectedFile.upload("./upload.php");
};
// the file is starting to upload.
listener.onOpen = function(selectedFile:FileReference):Void {
_root.upWin.results_txt.text = String("Uploading " + selectedFile.name + "n");
};
listener.onHTTPError = function(file:FileReference, httpError:Number):Void {
_root.upWin.results_txt.text = String("HTTPError number: "+httpError +"nFile: "+ file.name);
}
listener.onIOError = function(file:FileReference):Void {
_root.upWin.results_txt.text = String("IOError: "+ file.name);
}
listener.onSecurityError = function(file:FileReference, errorString:String):Void {
_root.upWin.results_txt.text = String("SecurityError: "+SecurityError+"nFile: "+ file.name);
}
listener.onProgress = function(file:FileReference, bytesLoaded:Number, bytesTotal:Number):Void {
upWin.loadBar._width = Number(bytesLoaded)/Number(bytesTotal)*300;
}
// the file has uploaded
listener.onComplete = function(selectedFile:FileReference):Void {
upWin.results_txt.text = String("Upload finished.nNow downloading " + selectedFile.name + " to playern");
if(position_txt.text == String("Front")){
attachMovie("trans", "transHolder", -16161, {_x:150, _y:120});
downloadImage1(selectedFile.name);
}else{
if(position_txt.text == String("Back")){
attachMovie("trans2", "transHolder2", -16162, {_x:450, _y:120});
downloadImage2(selectedFile.name);
}else{
if(position_txt.text == String("LSleeve")){
attachMovie("trans3", "transHolder3", -16163, {_x:150, _y:120});
downloadImage3(selectedFile.name);
}else{
if(position_txt.text == String("RSleeve")){
attachMovie("trans4", "transHolder4", -16164, {_x:450, _y:120});
downloadImage4(selectedFile.name);
}
}
}
}
Itotal_txt.text = Number(3.00);
_root.upWin._x = 2000;
};
var imageFile:FileReference = new FileReference();
imageFile.addListener(listener);
imageMovie.uploadBtn.onPress = uploadImage;
imageMovie.uploadBtn2.onPress = uploadImage;
imageMovie2.uploadBtn3.onPress = uploadImage;
imageMovie2.uploadBtn4.onPress = uploadImage;
// Call the uploadImage() function, opens a file browser dialog.
function uploadImage(event:Object):Void {
imageFile.browse([{description: "Image Files", extension: "*.jpg;*.gif;*.png"}]);
}
// If the image does not download, the event objects total property
// will equal -1. In that case, display am error message
function imageDownloaded(event:Object):Void {
if(event.total == -1) {
_root.upWin.results_txt.text = String("error");
}
}
// show uploaded image in scrollPane
function downloadImage1(file:Object):Void {
transHolder.umbongo.loadMovie("./uploaded/" + file);
}
// show uploaded image in scrollPane
function downloadImage2(file:Object):Void {
transHolder2.umbongo2.loadMovie("./uploaded/" + file);
}
// show uploaded image in scrollPane
function downloadImage3(file:Object):Void {
transHolder3.umbongo3.loadMovie("./uploaded/" + file);
}
// show uploaded image in scrollPane
function downloadImage4(file:Object):Void {
var randomNum:Number = Math.round(Math.random()*(10000-0))+0;
transHolder4.umbongo4.loadMovie("./uploaded/" + file);
}
And the PHP is:
CODE:
move_uploaded_file($_FILES[Filedata][tmp_name], ./uploaded/.$_FILES[Filedata][name]);
copy(./uploaded/.$_FILES[Filedata][name], ./timeStamped/.time().$_FILES[Filedata][name]);
?>
If anyone can think of a way to sort this out - itd be most appreciated - im tearing my hair out over this!
Thanks,
DrGonzo.
Topic Replies: 0
Read More...
[Source: Ozzu - Posted by FreeAutoBlogger]
No comments:
Post a Comment