Groups | Blog | Home
all groups > flash actionscript > january 2006 >

flash actionscript : upload with php and flash


Motion Maker
1/24/2006 8:51:15 PM
The second line is relative to the folder of the PHP script on the =
server.

=20
<?
if ($_FILES['Filedata']['name']) {
$uploadDir =3D "mij/";
$uploadFile =3D $uploadDir . basename($_FILES['Filedata']['name']);
move_uploaded_file($_FILES['Filedata']['tmp_name'], $uploadFile);
}


--=20
Lon Hosford
www.lonhosford.com
May many happy bits flow your way!
[quoted text, click to view]
although the output says all done in the onComplete I have no file in =
mij=20
Motion Maker
1/24/2006 8:53:04 PM
Also create write permissions need to be on for PHP. Generally PHP will =
have those permissions but creating a test PHP script that creates and =
writes to a file. Test that first without Flash.=20
--=20
Lon Hosford
www.lonhosford.com
May many happy bits flow your way!
[quoted text, click to view]
although the output says all done in the onComplete I have no file in =
mij=20
directory.

this is my php
<?
if ($_FILES['Filedata']['name']) {
$uploadDir =3D "images/";
$uploadFile =3D $uploadDir . basename($_FILES['Filedata']['name']);
move_uploaded_file($_FILES['Filedata']['tmp_name'], $uploadFile);
}
?>


//import the FileReference Object
_global.path =3D "http://localhost/merch";
import flash.net.FileReference;
//initial settings
uploadFile_mc.enabled =3D false;
//the FileReference object
var file_fr:FileReference =3D new FileReference();
//object for listening to for FileReference events
var list_obj:Object =3D new Object();
list_obj.onSelect =3D function() {
if (file_fr.size/1024<150) {
uploadFile_mc.enabled =3D true;
name_txt.text =3D file_fr.name;
} else {
name_txt.text =3D "max 150kb.";
uploadFile_mc.enabled =3D false
}
};
list_obj.onComplete =3D function() {
name_txt.text =3D "All Done";
rec_mc.clear();
uploadFile_mc.enabled =3D false;
};
list_obj.onProgress =3D function(bytesTotal, bytesLoaded) {
var percent =3D bytesLoaded/file_fr.size;
drawRec(percent);
};
//if a user selects cancel
list_obj.onCancel =3D function() {
name_txt.text =3D "Cancel was selected";
};
//if there is an IO error
list_obj.onIOError =3D function(fileRef) {
name_txt.text =3D "IO error with "+fileRef.name;
};
//security error problem
list_obj.onSecurityError =3D function(fileRef, error) {
name_txt.text =3D "Security error with "+fileRef.name+":"+error;
};
//httpError
list_obj.onHTTPError =3D function(fileRef:FileReference, error:Number) =
{
name_txt.text +=3D "HTTP error: with "+fileRef.name+":error #"+error;
};
//attach the listener
file_fr.addListener(list_obj);
//the event for the browse button
browse_mc.onRelease =3D function() {
file_fr.browse([{description:"Images",=20
extension:"*.JPG;*.jpg;*.psd;*.gif;*.png"}]);
};
//the event for the upload button
uploadFile_mc.onRelease =3D function() {
file_fr.upload(path+"/_php/upload.php");//?naam=3D"+file_fr.name
rec_mc.fillColor =3D Math.random()*0x1000000;
};
//drawing the rectangle
function drawRec(per) {
rec_mc.clear();
rec_mc.lineStyle(0);
rec_mc.beginFill(rec_mc.fillColor, 70);
rec_mc.lineTo(per*rec_mc._width, 0);
rec_mc.lineTo(per*rec_mc._width, rec_mc._height);
rec_mc.lineTo(0, 30);
rec_mc.lineTo(0, 0);
rec_mc.endFill();
DrEv1l
1/24/2006 11:50:11 PM
although the output says all done in the onComplete I have no file in mij
directory.

this is my php
<?
if ($_FILES['Filedata']['name']) {
$uploadDir = "images/";
$uploadFile = $uploadDir . basename($_FILES['Filedata']['name']);
move_uploaded_file($_FILES['Filedata']['tmp_name'], $uploadFile);
}
?>


//import the FileReference Object
_global.path = "http://localhost/merch";
import flash.net.FileReference;
//initial settings
uploadFile_mc.enabled = false;
//the FileReference object
var file_fr:FileReference = new FileReference();
//object for listening to for FileReference events
var list_obj:Object = new Object();
list_obj.onSelect = function() {
if (file_fr.size/1024<150) {
uploadFile_mc.enabled = true;
name_txt.text = file_fr.name;
} else {
name_txt.text = "max 150kb.";
uploadFile_mc.enabled = false
}
};
list_obj.onComplete = function() {
name_txt.text = "All Done";
rec_mc.clear();
uploadFile_mc.enabled = false;
};
list_obj.onProgress = function(bytesTotal, bytesLoaded) {
var percent = bytesLoaded/file_fr.size;
drawRec(percent);
};
//if a user selects cancel
list_obj.onCancel = function() {
name_txt.text = "Cancel was selected";
};
//if there is an IO error
list_obj.onIOError = function(fileRef) {
name_txt.text = "IO error with "+fileRef.name;
};
//security error problem
list_obj.onSecurityError = function(fileRef, error) {
name_txt.text = "Security error with "+fileRef.name+":"+error;
};
//httpError
list_obj.onHTTPError = function(fileRef:FileReference, error:Number) {
name_txt.text += "HTTP error: with "+fileRef.name+":error #"+error;
};
//attach the listener
file_fr.addListener(list_obj);
//the event for the browse button
browse_mc.onRelease = function() {
file_fr.browse([{description:"Images",
extension:"*.JPG;*.jpg;*.psd;*.gif;*.png"}]);
};
//the event for the upload button
uploadFile_mc.onRelease = function() {
file_fr.upload(path+"/_php/upload.php");//?naam="+file_fr.name
rec_mc.fillColor = Math.random()*0x1000000;
};
//drawing the rectangle
function drawRec(per) {
rec_mc.clear();
rec_mc.lineStyle(0);
rec_mc.beginFill(rec_mc.fillColor, 70);
rec_mc.lineTo(per*rec_mc._width, 0);
rec_mc.lineTo(per*rec_mc._width, rec_mc._height);
rec_mc.lineTo(0, 30);
rec_mc.lineTo(0, 0);
rec_mc.endFill();
}
DrEv1l
1/25/2006 12:00:00 AM
I don't know how to test my php on its own without flash

Motion Maker
1/25/2006 6:14:12 PM
Create a file test_make_file.php.Place in a folder on your server.Load =
it from the web browser with http://. If no errors you will not see =
messages but if you look in the folder on your server you will see a =
file names =
test.txt<?php/*----------------------------------------------------------=
------------ Optional dump to server side text file. Reminder your =
server folder needs to allow write and create permission for the file =
name =
selected.----------------------------------------------------------------=
-------- File name to dump data from =
Flash--------------------------------------------------------------------=
-*/$filename =3D =
"test.txt";/*------------------------------------------------------------=
---------- Open stream to =
file---------------------------------------------------------------------=
*/$fp =3D fopen( =
$filename,"w+");/*-------------------------------------------------------=
--------------- Write to =
stream-------------------------------------------------------------------=
----- Any text into file for testing in case nothing is =
received-----------------------------------------------------------------=
----*/fwrite ( $fp, "Testing" =
);/*---------------------------------------------------------------------=
- Close =
stream-------------------------------------------------------------------=
--*/fclose( $fp );?> =20
--=20
Lon Hosford
www.lonhosford.com
May many happy bits flow your way!
[quoted text, click to view]
I don't know how to test my php on its own without flash

AddThis Social Bookmark Button