Welcome, Guest. Please login or register.
Did you miss your activation email?
05/22/12, 06:01
Home Help Search Login Register
News: Parsley Flex framework review featuring quiz application, in our Flex frameworks series
Flex SDK 4.5 mobile roadmap: begin with your mobile development
Swiz Flex framework review featuring quiz application
New homepage we release our new Homepage, take a look ...

+  Flash-db
|-+  General
| |-+  Flash and AS 3 (Moderators: papachan, kofi addaquay)
| | |-+  upload using asc3
0 Members and 1 Guest are viewing this topic. « previous next »
Pages: [1] 2 Print
Author Topic: upload using asc3  (Read 4833 times)
Alan
Server what's that
*
Posts: 36


View Profile Email
« on: 06/30/08, 14:51 »

Quote
package {
    import flash.display.Sprite;
    import flash.events.*;
    import flash.net.FileReference;
    import flash.net.FileReferenceList;
 
    public class FileReferenceListExample extends Sprite {
        public static var LIST_COMPLETE:String = "listComplete";
        public function FileReferenceListExample() {
            initiateFileUpload();
        }

        private function initiateFileUpload():void {
            var fileRef:CustomFileReferenceList = new CustomFileReferenceList();
            fileRef.addEventListener(FileReferenceListExample.LIST_COMPLETE, listCompleteHandler);
            fileRef.browse(fileRef.getTypes());
        }

        private function listCompleteHandler(event:Event):void {
            trace("listCompleteHandler");
        }
    }
}
 
import flash.events.*;
import flash.net.FileReference;
import flash.net.FileReferenceList;
import flash.net.FileFilter;
import flash.net.URLRequest;
 
class CustomFileReferenceList extends FileReferenceList {
    private var uploadURL:URLRequest;
    private var pendingFiles:Array;

    public function CustomFileReferenceList() {
        uploadURL = new URLRequest();
        uploadURL.url = "http://localhost/test/up.php";
        initializeListListeners();
    }

    private function initializeListListeners():void {
        addEventListener(Event.SELECT, selectHandler);
        addEventListener(Event.CANCEL, cancelHandler);
    }

    public function getTypes():Array {
        var allTypes:Array = new Array();
        allTypes.push(getImageTypeFilter());
        allTypes.push(getTextTypeFilter());
        return allTypes;
    }
 
    private function getImageTypeFilter():FileFilter {
        return new FileFilter("Images (*.jpg, *.jpeg, *.gif, *.png)", "*.jpg;*.jpeg;*.gif;*.png");
    }
 
    private function getTextTypeFilter():FileFilter {
        return new FileFilter("Text Files (*.txt, *.rtf)", "*.txt;*.rtf");
    }
 
    private function doOnComplete():void {
        var event:Event = new Event(FileReferenceListExample.LIST_COMPLETE);
        dispatchEvent(event);
    }
 
    private function addPendingFile(file:FileReference):void {
        trace("addPendingFile: name=" + file.name);
        pendingFiles.push(file);
        file.addEventListener(Event.OPEN, openHandler);
        file.addEventListener(Event.COMPLETE, completeHandler);
        file.addEventListener(IOErrorEvent.IO_ERROR, ioErrorHandler);
        file.addEventListener(ProgressEvent.PROGRESS, progressHandler);
        file.addEventListener(SecurityErrorEvent.SECURITY_ERROR, securityErrorHandler);
        file.upload(uploadURL);
    }
 
    private function removePendingFile(file:FileReference):void {
        for (var i:uint; i < pendingFiles.length; i++) {
            if (pendingFiles.name == file.name) {
                pendingFiles.splice(i, 1);
                if (pendingFiles.length == 0) {
                    doOnComplete();
                }
                return;
            }
        }
    }
 
    private function selectHandler(event:Event):void {
        trace("selectHandler: " + fileList.length + " files");
        pendingFiles = new Array();
        var file:FileReference;
        for (var i:uint = 0; i < fileList.length; i++) {
            file = FileReference(fileList);
            addPendingFile(file);
        }
    }
 
    private function cancelHandler(event:Event):void {
        var file:FileReference = FileReference(event.target);
        trace("cancelHandler: name=" + file.name);
    }
 
    private function openHandler(event:Event):void {
        var file:FileReference = FileReference(event.target);
        trace("openHandler: name=" + file.name);
    }
 
    private function progressHandler(event:ProgressEvent):void {
        var file:FileReference = FileReference(event.target);
        trace("progressHandler: name=" + file.name + " bytesLoaded=" + event.bytesLoaded + " bytesTotal=" + event.bytesTotal);
    }
 
    private function completeHandler(event:Event):void {
        var file:FileReference = FileReference(event.target);
        trace("completeHandler: name=" + file.name);
        removePendingFile(file);
    }
 
    private function httpErrorHandler(event:Event):void {
        var file:FileReference = FileReference(event.target);
        trace("httpErrorHandler: name=" + file.name);
    }
 
    private function ioErrorHandler(event:Event):void {
        var file:FileReference = FileReference(event.target);
        trace("ioErrorHandler: name=" + file.name);
    }
 
    private function securityErrorHandler(event:Event):void {
        var file:FileReference = FileReference(event.target);
        trace("securityErrorHandler: name=" + file.name + " event=" + event.toString());
    }
}

I have the script working no errors,  but when I check the upload folder the file is not there

selectHandler: 1 files
addPendingFile: name=Image_Icon.jpg
openHandler: name=Image_Icon.jpg
progressHandler: name=Image_Icon.jpg bytesLoaded=877 bytesTotal=877
completeHandler: name=Image_Icon.jpg
listCompleteHandler


This is the output I get when click for upload.

Anyone have any idea why I can find the file I've just uploaded.



My php script

Quote
<?
$tmp=$_FILES['Filedata']['tmp_name'];
$name=$_FILES['Filedata']['name'];
move_uploaded_file($tmp,dirname(__FILE__) . '/uploads/' . $name);

?>

I have also trie cfm but I get errors I dont have a clue why the single line of script was from the adobe live docs as well.

Quote
<cffile action="upload" filefield="Filedata" destination="#ExpandPath('./')#"
nameconflict="OVERWRITE" />


I have a crossdomain.xml

Quote
<?xml version="1.0"?>

   <!DOCTYPE cross-domain-policy SYSTEM "http://www.macromedia.com/xml/dtds/cross-domain-policy.dtd">

   <cross-domain-policy>

   <allow-access-from domain="*" />

   </cross-domain-policy>

I would appreciate any help  Grin

« Last Edit: 07/01/08, 08:35 by Alan » Logged
Jorge Solis
Administrator
Systems Administrator
*****
Posts: 14600


View Profile
« Reply #1 on: 07/01/08, 05:26 »

Have the upload folder write permissons?

Jorge
Logged

Alan
Server what's that
*
Posts: 36


View Profile Email
« Reply #2 on: 07/01/08, 07:50 »

The permission seem to be ok because I have uploaded with a simple html and php script to the same folder but no success with the swf uploader.

However I don't know how the set permission properly ?

I am using vista with wamp serve

Thanks for your help again Jorge.
Logged
Jorge Solis
Administrator
Systems Administrator
*****
Posts: 14600


View Profile
« Reply #3 on: 07/01/08, 08:02 »

Your code looks fine, can you check if the movie finds the PHP script? Add some log (just write to a txt file) or use Charles http://www.charlesproxy.com to sniff the conection

Jorge
Logged

Alan
Server what's that
*
Posts: 36


View Profile Email
« Reply #4 on: 07/01/08, 08:30 »

I downloaded Charles great program thanks Jorge once again.

This was the response: 

<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">
<html><head>
<title>404 Not Found</title>
</head><body>
<h1>Not Found</h1>
<p>The requested URL /crossdomain.xml was not found on this server.</p>
</body></html>


It looks Like the crossdomain.xml but I do have the file in the same directory as everything else.
« Last Edit: 07/01/08, 08:37 by Alan » Logged
Ronald Wernecke
Administrator
Systems Administrator
*****
Posts: 6175


View Profile WWW Email
« Reply #5 on: 07/01/08, 08:58 »

crossdomain has to reside in the root of the webpresentation and reachable by servername/crossdomain.xml
Logged

happy flashing
Cool
Ronald
Alan
Server what's that
*
Posts: 36


View Profile Email
« Reply #6 on: 07/01/08, 10:29 »

Thanks Ronald for your help can you tell what I have to do with crossdomain.xml because I am lost at the moment.

I have also tried to ftp using cuteFtp8 to my localHost and when I have tried to CHMOD my root folder in the ftp program my windows settings for vista will not allow me to. Do you know how to set the vista opertaing system to allow CHMOD on ftp I've tried all the things I know which is not allot.

ERROR:>      [01/07/2008 16:12:12] Control connection closed.


Tried right click make folder ready for archive. // nothing changed

Tried sharing folder with local users // noting changed

Tried setting permission to fullcontrol // nothing changed

I am completely lost

Logged
Ronald Wernecke
Administrator
Systems Administrator
*****
Posts: 6175


View Profile WWW Email
« Reply #7 on: 07/01/08, 10:35 »

you are running the server under windows vista?

be aware, accessing right in windows are weird Wink - and even weirder in vista Wink

Anyway - everyone is not internet user - but internet user needs the access you want to give your users using your application.

Make sure your swf lies in the same domain, your other files are. Then you dont need a crossxmlfile.

Allways start your swf from the server, even when the server is your local machine.
Logged

happy flashing
Cool
Ronald
Alan
Server what's that
*
Posts: 36


View Profile Email
« Reply #8 on: 07/01/08, 11:18 »

Thanks again I am only using my local machine to test thing not going to use it online like just learning.

I have tried running the swf file directly from my wamp serve /test folder and I am still getting no joy with a successful upload with my swf file but I can succesfully upload with a basic html and php script.  Angry

I am very confused because if my scripts are ok then why can I upload with html and php but not action script and php  Huh

I think its something to do with permission on my vista operating system because I can't use the CHMOD option (its not selectable) on ftp program for my wamp serve local host.

Please Help Me  Cry

Logged
Alan
Server what's that
*
Posts: 36


View Profile Email
« Reply #9 on: 07/01/08, 11:22 »

just found out the CHMOD is not for Windows. Well thet explain why I can't CHMOD but I still can upload a file to my local host
Logged
Jorge Solis
Administrator
Systems Administrator
*****
Posts: 14600


View Profile
« Reply #10 on: 07/01/08, 11:29 »

Quote
I have tried running the swf file directly from my wamp serve /test folder

Just to be clear, that means you open your browser and type http://localhost/test/whatever.html , rigth?

Jorge
Logged

Alan
Server what's that
*
Posts: 36


View Profile Email
« Reply #11 on: 07/01/08, 12:39 »

Yes I have tired opening like this http://localhost/test/FileReference_upload.html

I have tried opening the swf;
I have tried running from Flash CS3;
I have tried running the html from the root test folder;
and Like you said running from browser  http://localhost/test/FileReference_upload.html ;

Head is spinning  Huh
Logged
Jorge Solis
Administrator
Systems Administrator
*****
Posts: 14600


View Profile
« Reply #12 on: 07/01/08, 13:04 »

If your request hits the PHP file, then you should see on Charles, and also any error

Jorge
Logged

Alan
Server what's that
*
Posts: 36


View Profile Email
« Reply #13 on: 07/01/08, 13:35 »

It doesn't seem to hit the up.php file for some reason.

localHost//

             test//
                    http://localhost/score/FileReference_upload.html
                    http://localhost/score/AC_RunActiveContent.js
                    http://localhost/score/FileReference_upload.swf


Should should the FileReference_upload.as show file as well ?

Logged
Jorge Solis
Administrator
Systems Administrator
*****
Posts: 14600


View Profile
« Reply #14 on: 07/01/08, 13:48 »

When you select a file and the upload finishes, up.php should appear on Charles
as files are code that is merged inside the swf file at compile time, so not as should be there (also is not neccesary to upload any as file to your server)

Jorge
Logged

Pages: [1] 2 Print 
« previous next »
Jump to:  


Powered by MySQL Powered by PHP Powered by SMF 1.1.16 | SMF © 2011, Simple Machines Valid XHTML 1.0! Valid CSS!