A Flash Developer Resource Site

Results 1 to 11 of 11

Thread: ASP & PHP fileupload from Flash ??

  1. #1
    Member
    Join Date
    Aug 2001
    Location
    The Netherlands
    Posts
    67

    ASP & PHP fileupload from Flash ??

    Hi There,

    I've found some really great scripts (ASP and PHP) that can upload files to a webserver. The problem is that you must browse with a HTML-file.
    I can't seem to convert this HTML-form to flash.... Load Variables, Get URL all don't seem to work.

    Here is the HTML-script (from the PHP-version):
    <HTML>
    <HEAD>
    <TITLE>Movie2</TITLE>
    </HEAD>
    <BODY bgcolor="#FFFFFF">
    <form action='upload.php' method='post' enctype='multipart/form-data'>

    <table cellspacing='10' style='background: #DDD; border: solid #009;
    border-width: .3em 0 .5em 0;'>
    <tr>
    <th colspan='2' style='background: #BBB; color: #000;
    text-align: center; padding: .3em;'>File Upload</th>
    </tr>
    <tr>
    <td style='vertical-align: middle'><b>FILER &gt;</b></td>
    <td><input type='file' name='file' /></td>
    </tr>
    <tr>
    <td colspan='2' style='text-align: right;'><input type='submit'
    value='Submit' /></td>
    </tr>
    </table>

    </form>
    </BODY>
    </HTML>

    AND THE PHP-SCRIPT:
    <?php
    if ($HTTP_POST_FILES['file']['size'] < 50000)
    {
    move_uploaded_file($HTTP_POST_FILES['file']['tmp_name'],
    'uploads/' . $HTTP_POST_FILES['file']['name']);
    echo '&status=ok&';
    } else
    {
    echo '&status=error&';
    }
    ?>

    I also tried calling the php-URL direct but this also won't work;
    http://www.domain.com/upload.php?file=C:\pics\pic1.jpg

    Any suggestions?

    Jip

  2. #2
    Registered User
    Join Date
    Feb 2001
    Posts
    13,041
    Hi,

    you are right - flash does not support file uploads (and if it did, there would either be an intervening dialog box "do you really want to upload" presented by flash player, or some real concerns about movies stealing your data)
    So you only can try to integrate that html form with your flash design. The common way is a html popup with a browse button, and it is working with most browsers, the other common way hides the browse button via javascripts and only works with the internet exploder

    Musicman

  3. #3
    Member
    Join Date
    Aug 2001
    Location
    The Netherlands
    Posts
    67
    Thanks for your reply Musicman,
    but the problem is that I don't want to work with an HTML-popup....

    I want the PHP-script allways to upload the same file from the users harddisk.... (allways C:\pics\uploadpic.jpg)... Is that maybe possible... so without the browse-buttons and all calling an HTML-page or some other script that tells the PHP-script that it must upload that file?

    # What kind of variables does that HTML-form pass to the PHP-script?
    # Has it something to do with the 'multipart/form-data' that you can't directly call the script? And can Flash do that also?

    Jip

  4. #4
    Member
    Join Date
    Aug 2001
    Location
    The Netherlands
    Posts
    67
    Maybe this question is better: Is there a way to post files with Flash ? Like the HTML-form does above...
    Or to auto-populate the 'file'-box in the HTML-form?

    Jip

  5. #5
    poet and narcisist argonauta's Avatar
    Join Date
    Nov 2001
    Location
    Under the bed
    Posts
    2,080
    someone has done it for images:

    http://www.yamago.net/components/

    it's a free component.
    my blog: blog.innocuo
    Sponsored by your mom.

  6. #6
    Registered User
    Join Date
    Feb 2001
    Posts
    13,041
    Hi,

    two comments on that:
    a) the yambrowser only works on certain systems
    b) the capability to fill in a html "file" form and submit it by scripting would mean that an arbitrary website can make your computer upload any file specified by name .. it could, e.g., try whether you have installed a common financial and homebanking program in its default location.
    In fact, said "capability" already existed for a while, but the hole was plugged.

    BTW: how about reverting the process and building a "specialized program" that logs into your website and uploads just that specific file?

    Musicman

  7. #7
    Member
    Join Date
    Aug 2001
    Location
    The Netherlands
    Posts
    67
    Thanks Musicman,

    I allready tried to make a specialized program with FSP, but the FTP-commands seem to have some problems on some computers...

    Is there really no scripting around this? What does that form actually submit? and can't flash submit a file then? Post moviecommand?

    Probably there is no solution... but I tried....

    Jip

  8. #8
    Registered User
    Join Date
    Feb 2001
    Posts
    13,041
    Hi,

    I have no idea about FSP, but have used a perl script successfully to communicate with a website (login, upload a file)

    Musicman

  9. #9
    Member
    Join Date
    Aug 2001
    Location
    The Netherlands
    Posts
    67
    Hi Musicman,

    Can you maybe post that script? And doesn't it work with a browse-button to select the file?

    Thanks a lot!

    Jip

  10. #10
    Registered User
    Join Date
    Feb 2001
    Posts
    13,041
    Hi,

    I can hardly post the full solution, so here is just a hint:
    The data sent to the server for an upload looks like this:
    Code:
    POST /test/upload.cgi HTTP/1.0
    Host: musicman
    Content-Type: multipart/form-data; boundary=---------------------------6774270164409796344
    Content-Length: 2777
    
    -----------------------------67742701644097963449346295
    Content-Disposition: form-data; name="upload"; filename="u2.jpg"
    Content-Type: image/jpeg
    
    .... here comes (binary) file data ...
    -----------------------------67742701644097963449346295
    Content-Disposition: form-data; name="other"
    
    myval
    -----------------------------67742701644097963449346295--
    The "other" part is the result of sending a normal input field set to "myval"
    So a sending script would
    a) determine a boundary that does not occur within data (common practise is to pick something random, better choice would be to verify against the files)
    b) make up a message to send to server
    c) use whatever means are available to connect to server and send; with perl this is a socket and connect call
    d) read response from server and handle it.
    If you can design the remote side as well, best choice would be to put authentication, if any, into the form.
    If the form is protected by basic auth , the auth data would have to be added to the request header as well.

    This is meant for a _local_ app, so it does not even touch the W3C concerns about privacy and browse buttons - unless you are using an OS that allows remote websites to run your local programs

    Musicman
    Last edited by Musicman; 04-19-2004 at 02:49 AM.

  11. #11
    Member
    Join Date
    Aug 2001
    Location
    The Netherlands
    Posts
    67
    Thanks Musicman,

    I'm gonna work on that one....
    In the mean time I've found the problem I had with FSP ftp-commands (great tool by the way).

    Thanks a lot,
    Jip

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center