?
Solved

Transition from PHP to ASP.net

Posted on 2010-11-11
4
Medium Priority
?
744 Views
Last Modified: 2012-05-10
Hi.

I'm starting to code in ASP.NET, and i have the following question.

I want to code a program to upload a file using "actionscript 2.0" ( flash.net.FileReference) on VB.NET; right now, i know how to do this using Perl and PHP ( "move_uploaded_file($_FILES['Filedata']['tmp_name'], "./imgage_files/".$_FILES['Filedata']['name'])"),
but i can't find how to accomplish the same task using this language.

I hope you could help me, and thank you very much.
0
Comment
Question by:kalvillo
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
4 Comments
 

Expert Comment

by:tzuhsun
ID: 34117415
Hi i can't give you a quick answer as I no idea right now.

But you can try search in goole by uing such phrase:
"ASP.net equivalient to move_uploaded_file()"

most of the time would not disappoint you.
0
 
LVL 7

Accepted Solution

by:
niralshah earned 2000 total points
ID: 34119333
See the attached code.
flash script file
package
{
    import flash.display.BitmapData;
    import flash.display.MovieClip;
    import flash.events.MouseEvent;
    import flash.net.URLLoader;
    import flash.net.URLRequest;
    import flash.net.URLRequestMethod;
    import flash.net.URLVariables;
    import flash.utils.ByteArray;
    import fl.controls.Button;
    import com.adobe.images.JPGEncoder;
    import com.dynamicflash.util.Base64;


    public class Uploader extends MovieClip
    {
        // Reference to the button on the stage
        public var btnUpload:Button;

        // Encoder quality
        private var _jpegQuality:int = 100;

        // Path to the upload script
        private var _uploadPath:String = "/upload.aspx";

        public function Uploader()
        {
                btnUpload.addEventListener(MouseEvent.CLICK, buttonClick);
        }

        private function buttonClick(e:MouseEvent):void
        {
                       // Create a new BitmapData object the size of the upload button.
                       // We're going to send the image of the button to the server.
                var image:BitmapData = new BitmapData(btnUpload.width, btnUpload.height);
                       // Draw the button into the BitmapData
                image.draw(btnUpload);

                       // Encode the BitmapData into a ByteArray
                var enc:JPGEncoder = new JPGEncoder(_jpegQuality);
                var bytes:ByteArray = enc.encode(image);

                       // and convert the ByteArray to a Base64 encoded string
                var base64Bytes:String = Base64.encodeByteArray(bytes);

                       // Add the string to a URLVariables object
                var vars:URLVariables = new URLVariables();
                vars.imageData = base64Bytes;

                // and send it over the wire via HTTP POST
                var url:URLRequest = new URLRequest(_uploadPath);
                url.data = vars;
                url.method = URLRequestMethod.POST;

                var loader:URLLoader = new URLLoader();
                loader.load(url);
        }
    }
}


asp.net code upload.aspx page

using System;
using System.IO;

public partial class upload : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        // Get the data from the POST array
        string data = Request.Form["imageData"];

        // Decode the bytes from the Base64 string
        byte[] bytes = Convert.FromBase64String(data);

        // Write the jpeg to disk
        string path = Server.MapPath("~/save.jpg");
        File.WriteAllBytes(path, bytes);

        // Clear the response and send a Flash variable back to the URL Loader
        Response.Clear();
        Response.ContentType = "text/plain";
        Response.Write("ok=ok");
    }
}

Open in new window

0
 

Author Comment

by:kalvillo
ID: 34123470
niralshah> that's not exactly what i'm looking for...

Right now, i have the following Flash code to "browse" my files:

import flash.net.FileReference;

_root.http_file = "http://myDom.com/upload.php";

// start exploration
btnListener.click = function(eventObj:Object) {
	var fileRef:FileReference = new FileReference();
	fileRef.addListener(fileListener);
	fileRef.browse(fileTypes);
}

//send file selected
fileListener.onSelect = function(file:FileReference):Void {
   resultsTxtField.text += "File Selected: " + file.name;
   if(!file.upload(_root.http_file)) {
       resultsTxtField.text += "Upload dialog failed to open.\n";
   }
}

Open in new window


When you select the desired file in the dialog box, Flash sends the file to the following code in PHP:

<?php
	move_uploaded_file($_FILES['Filedata']['tmp_name'], "./file_images/".$_FILES['Filedata']['name']);
	chmod("./file_images/".$_FILES['Filedata']['name'], 0777);
?>

Open in new window


This PHP code delivers the file into the server.

What i need is a code in ASP.NET that do the same thing than the PHP one... i mean, the Flash code works fine as it is, i just need a code in ASP to conect with such flash code.
0
 

Author Comment

by:kalvillo
ID: 34124993
niralshah> by the way.. that code that you send me, do you have it on "Action Script 2"?... it could be handy for another process.
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Just a quick little trick I learned recently.  Now that I'm using jQuery with abandon in my asp.net applications, I have grown tired of the following syntax:      (CODE) I suppose it just offends my sense of decency to put inline VBScript on a…
User art_snob (http://www.experts-exchange.com/M_6114203.html) encountered strange behavior of Android Web browser on his Mobile Web site. It took a while to find the true cause. It happens so, that the Android Web browser (at least up to OS ver. 2.…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
Six Sigma Control Plans

764 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question