jeffnovis
04-21-2006, 09:05 PM
Hi,
Thanks for reading this. I'm new to ActionScript and PHP so I expect this will be something quite simple but I've been racking my brains for hours and I can't see the problem. I'm trying to upload a user-selected image file from a Flash movie and then display the image in a ScrollPane in the movie (actually I'm eventually going to create thumbnails for display so I'm just using small images to test).
The upload is done with the FileReference object (adapted from a script I found on the Web) and a simple PHP upload script which stores the name of uploaded image as $_SESSION['image']. This works fine.
In the (ActionScript)"onComplete" method for my upload, I've put the "load" method of a LoadVars object that tries to get the name of the uploaded image from a second PHP script which tries to access $_SESSION['image']. However, for some reason $_SESSION['image'] is not set. I've arranged for the second PHP script to pass $_SESSION['image'] to Flash if it is set, or a "No image" GIF if it's not.
Can anyone see why $_SESSION['image'] is not being saved to the PHP SESSION, or if it is, why the second PHP file (image_data.php) can't read it?
Heres the URL to try out: http://www.winkleweb.org/my_uploader/my_uploader.html
Here's the ActionScript file:
import mx.utils.Delegate;
import mx.controls.TextArea;
import mx.controls.ProgressBar;
import mx.controls.Button;
import mx.containers.ScrollPane;
import flash.net.FileReference;
var textArea:TextArea;
var progressBar:ProgressBar;
var browse_btn:Button;
var upload_btn:Button;
var imagePane:ScrollPane;
var fileRef:FileReference;
var uploadURL:String = "http://www.winkleweb.org/my_uploader/upload.php";
var imageData:LoadVars;
function onLoad():Void
{
textArea.fontSize = 15;
progressBar.mode = "manual";
progressBar.fontSize = 14;
progressBar.color = 0x848384;
progressBar.visible = false;
browse_btn.label = "Browse";
browse_btn.onPress = Delegate.create(this, this.browse);
upload_btn.label = "Upload";
upload_btn.onPress = Delegate.create(this, this.upload);
imagePane.contentPath = "";
fileRef = new FileReference();
fileRef.addListener(this);
}
imageData = new LoadVars();
imageData.onLoad = function()
{
insertImage();
};
insertImage = function()
{
imagePane.contentPath = imageData.scrollPaneImage;
};
function browse():Void
{
var success:Boolean;
success = this.fileRef.browse([{description: "Image Formats (*.jpg, *.jpeg)", extension: "*.jpg;*.jpeg", macType: "JPEG;jp2_"}]);
if(success == false)
{
textArea.text = "OS window failed to open";
}
}
function upload():Void
{
var success:Boolean;
success = this.fileRef.upload("http://www.winkleweb.org/my_uploader/upload.php");
if(success == false)
{
textArea.text = "upload process failed to start";
}
}
function onSelect(fileRef:FileReference):Void
{
textArea.text = fileRef.name + " (";
textArea.text += "size: " + fileRef.size + " kb)";
}
function onOpen(fileRef:FileReference):Void
{
textArea.text = "upload started";
}
function onProgress(fileRef:FileReference, loaded_num:Number, total_num:Number):Void
{
progressBar.visible = true;
progressBar.setProgress(loaded_num, total_num);
}
function onComplete(fileRef:FileReference):Void
{
progressBar.setProgress(100, 100);
progressBar.visible = false;
textArea.text = "upload successful";
imageData.load("http://www.winkleweb.org/my_uploader/image_data.php");
}
function onCancel():Void
{
textArea.text = "Cancelled";
}
function onHTTPError(fileRef:FileReference):Void
{
textArea.text = "onHTTPError: " + fileRef.name;
}
function onIOError(fileRef:FileReference):Void
{
textArea.text = "onIOError: " + fileRef.name;
}
function onSecurityError(fileRef:FileReference, error_str:String):Void
{
textArea.text = "onSecurityError: " + fileRef.name + " error : " + error_str;
}
Here's the upload.php file:
session_start();
$uploadDir = "uploads/";
$_SESSION['image'] = $_FILES['Filedata']['name'];
$uploadpath = $uploadDir . $_SESSION['image'];
function move_file(uploadedfile)
{
move_uploaded_file($_FILES['Filedata']['tmp_name'], uploadedfile);
}
move_file($uploadpath);
and here's the image_data.php file used to get the LoadVars data:
session_start();
if (isset($_SESSION['image']))
{
$user_image = "uploads/" . $_SESSION['image'];
}
else
{
$user_image = "uploads/" . "no_image.gif";
}
print("&scrollPaneImage=$user_image");
If you want to test this on your server you can download all the files from http://www.winkleweb.org/my_uploader/my_uploader.zip
Thanks again for having a look at this.
Cheers,
Jeff
Thanks for reading this. I'm new to ActionScript and PHP so I expect this will be something quite simple but I've been racking my brains for hours and I can't see the problem. I'm trying to upload a user-selected image file from a Flash movie and then display the image in a ScrollPane in the movie (actually I'm eventually going to create thumbnails for display so I'm just using small images to test).
The upload is done with the FileReference object (adapted from a script I found on the Web) and a simple PHP upload script which stores the name of uploaded image as $_SESSION['image']. This works fine.
In the (ActionScript)"onComplete" method for my upload, I've put the "load" method of a LoadVars object that tries to get the name of the uploaded image from a second PHP script which tries to access $_SESSION['image']. However, for some reason $_SESSION['image'] is not set. I've arranged for the second PHP script to pass $_SESSION['image'] to Flash if it is set, or a "No image" GIF if it's not.
Can anyone see why $_SESSION['image'] is not being saved to the PHP SESSION, or if it is, why the second PHP file (image_data.php) can't read it?
Heres the URL to try out: http://www.winkleweb.org/my_uploader/my_uploader.html
Here's the ActionScript file:
import mx.utils.Delegate;
import mx.controls.TextArea;
import mx.controls.ProgressBar;
import mx.controls.Button;
import mx.containers.ScrollPane;
import flash.net.FileReference;
var textArea:TextArea;
var progressBar:ProgressBar;
var browse_btn:Button;
var upload_btn:Button;
var imagePane:ScrollPane;
var fileRef:FileReference;
var uploadURL:String = "http://www.winkleweb.org/my_uploader/upload.php";
var imageData:LoadVars;
function onLoad():Void
{
textArea.fontSize = 15;
progressBar.mode = "manual";
progressBar.fontSize = 14;
progressBar.color = 0x848384;
progressBar.visible = false;
browse_btn.label = "Browse";
browse_btn.onPress = Delegate.create(this, this.browse);
upload_btn.label = "Upload";
upload_btn.onPress = Delegate.create(this, this.upload);
imagePane.contentPath = "";
fileRef = new FileReference();
fileRef.addListener(this);
}
imageData = new LoadVars();
imageData.onLoad = function()
{
insertImage();
};
insertImage = function()
{
imagePane.contentPath = imageData.scrollPaneImage;
};
function browse():Void
{
var success:Boolean;
success = this.fileRef.browse([{description: "Image Formats (*.jpg, *.jpeg)", extension: "*.jpg;*.jpeg", macType: "JPEG;jp2_"}]);
if(success == false)
{
textArea.text = "OS window failed to open";
}
}
function upload():Void
{
var success:Boolean;
success = this.fileRef.upload("http://www.winkleweb.org/my_uploader/upload.php");
if(success == false)
{
textArea.text = "upload process failed to start";
}
}
function onSelect(fileRef:FileReference):Void
{
textArea.text = fileRef.name + " (";
textArea.text += "size: " + fileRef.size + " kb)";
}
function onOpen(fileRef:FileReference):Void
{
textArea.text = "upload started";
}
function onProgress(fileRef:FileReference, loaded_num:Number, total_num:Number):Void
{
progressBar.visible = true;
progressBar.setProgress(loaded_num, total_num);
}
function onComplete(fileRef:FileReference):Void
{
progressBar.setProgress(100, 100);
progressBar.visible = false;
textArea.text = "upload successful";
imageData.load("http://www.winkleweb.org/my_uploader/image_data.php");
}
function onCancel():Void
{
textArea.text = "Cancelled";
}
function onHTTPError(fileRef:FileReference):Void
{
textArea.text = "onHTTPError: " + fileRef.name;
}
function onIOError(fileRef:FileReference):Void
{
textArea.text = "onIOError: " + fileRef.name;
}
function onSecurityError(fileRef:FileReference, error_str:String):Void
{
textArea.text = "onSecurityError: " + fileRef.name + " error : " + error_str;
}
Here's the upload.php file:
session_start();
$uploadDir = "uploads/";
$_SESSION['image'] = $_FILES['Filedata']['name'];
$uploadpath = $uploadDir . $_SESSION['image'];
function move_file(uploadedfile)
{
move_uploaded_file($_FILES['Filedata']['tmp_name'], uploadedfile);
}
move_file($uploadpath);
and here's the image_data.php file used to get the LoadVars data:
session_start();
if (isset($_SESSION['image']))
{
$user_image = "uploads/" . $_SESSION['image'];
}
else
{
$user_image = "uploads/" . "no_image.gif";
}
print("&scrollPaneImage=$user_image");
If you want to test this on your server you can download all the files from http://www.winkleweb.org/my_uploader/my_uploader.zip
Thanks again for having a look at this.
Cheers,
Jeff