Solved

Transition from PHP to ASP.net

Posted on 2010-11-11
4
733 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
  • 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 500 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

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Problem to Popup 37 82
Duplicate a row 2 33
SQL to update characters in table column 6 31
Entity Framework 3 16
Today is the age of broadband.  More and more people are going this route determined to experience the web and it’s multitude of services as quickly and painlessly as possible. Coupled with the move to broadband, people are experiencing the web via …
I have been pestered over the years to produce and distribute regular data extracts, and often the request have explicitly requested the data be emailed as an Excel attachement; specifically Excel, as it appears: CSV files confuse (no Red or Green h…
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…
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.

744 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

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now