Jump to content

File and Variable upload through as3 to php


JaV
 Share

Recommended Posts

I am trying to get an swf to upload an image along with user information.

I was able to get the upload and variables send working individually, but together it stops with no visible errors.

The following is a link:

http://jarrodverhagen.com/upload/swfindex.htm

to a tutorial that is using almost identical code to mine, and has been used by others, but still will not work on my site.

Is there a reason supposedly correct code wouldn't work on my site?

The original link for the tutorial is:

http://www.developphp.com/Flash_tutoria ... sh_and_AS3

Link to comment
Share on other sites

You can get the files at the link provided:

http://www.developphp.com/Flash_tutorials/show_tutorial.php?tid=6&t=Browse_and_Upload_Files_Using_Flash_and_AS3

 

This is the AS3 code:

 

uploadMsg.visible = false;

var URLrequest:URLRequest = new URLRequest("http://www.[yoursite.com].com/uploader_script.php");

var imageTypes:FileFilter = new FileFilter("Images (*.jpg, *.jpeg, *.gif, *.png)", "*.jpg; *.jpeg; *.gif; *.png");

var textTypes:FileFilter = new FileFilter("Text Files (*.txt, *.rtf)", "*.txt; *.rtf");

var allTypes:Array = new Array(imageTypes, textTypes);

var fileRef:FileReference = new FileReference();

fileRef.addEventListener(Event.SELECT, syncVariables);

fileRef.addEventListener(Event.COMPLETE, completeHandler);

fileRef.addEventListener(ProgressEvent.PROGRESS, progressHandler);

browse_btn.addEventListener(MouseEvent.CLICK, browseBox);

upload_btn.addEventListener(MouseEvent.CLICK, uploadVars);

 

function browseBox(event:MouseEvent):void {

fileRef.browse(allTypes);

}

function uploadVars(event:MouseEvent):void {

uploadMsg.visible = true;

fileRef.upload(URLrequest);

upload_btn.visible = false;

}

function syncVariables(event:Event):void {

fileDisplay_txt.text = "" + fileRef.name;

blocker.visible = false;

upload_btn.visible = true;

progressBar.width = 2;

    var variables:URLVariables = new URLVariables();

    variables.todayDate = new Date();

    variables.Name = "Dude"; // This could be an input field variable like in my contact form tutorial : )

variables.Email = "someDude@someEmail.com"; // This one the same

    URLrequest.method = URLRequestMethod.POST;

    URLrequest.data = variables;

}

function completeHandler(event:Event):void {

uploadMsg.visible = false;

blocker.visible = true;

    status_txt.text = fileRef.name + " has been uploaded.";

    fileDisplay_txt.text = "";

}

function progressHandler(event:ProgressEvent):void {

    progressBar.width = Math.ceil(200*(event.bytesLoaded/event.bytesTotal));

}

 

The php code:

 

<?php

$todayDate = $_POST['todayDate'];

$Name = $_POST['Name'];

$Email = $_POST['Email'];

$filename = $_FILES['Filedata']['name'];

$filetmpname = $_FILES['Filedata']['tmp_name'];

$fileType = $_FILES["Filedata"]["type"];

$fileSizeMB = ($_FILES["Filedata"]["size"] / 1024 / 1000);

move_uploaded_file($_FILES['Filedata']['tmp_name'], "images/".$filename);

$myFile = "logFile.txt";

$fh = fopen($myFile, 'a') or die("can't open file");

$stringData = "\n\ntodayDate: $todayDate  \n Name: $Name \n Email: $Email \n ssid: $ssid \n FileName: $filename \n TmpName: $filetmpname \n Type: $fileType \n Size: $fileSizeMB MegaBytes";

fwrite($fh, $stringData);

fclose($fh);

?>

 

All Script Written By: Adam Khoury @ www.developphp.com

 

So as far as most people are concerned this code works. But I can't get it working on my site unless I take out the the vars in AS3 and just upload(), or if i change the upload to a vars load(). But I need both for the code to do what I need. Any thoughts?

PS. This is not the code I am using for my site but it is almost the same.

Link to comment
Share on other sites

This thread is more than a year old.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.