Solved

Transition from PHP to ASP.net

Posted on 2010-11-11
4
741 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 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

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Html split(text) Part2 6 38
Vbscript Help Needed - Protecting Queries from special characters / SQL Injection 11 37
asp.net repeater server posting 5 35
asp.net mvc5 6 32
A quick way to get a menu to work on our website, is using the Menu control and assign it to a web.sitemap using SiteMapDataSource. Example of web.sitemap file: (CODE) Sample code to add to the page menu: (CODE) Running the application, we wi…
I was asked about the differences between classic ASP and ASP.NET, so let me put them down here, for reference: Let's make the introductions... Classic ASP was launched by Microsoft in 1998 and dynamically generate web pages upon user interact…
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…

738 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