Alpha Video Training
Results 1 to 5 of 5

Thread: Upload File on A5W page

  1. #1
    Member
    Real Name
    John Burt
    Join Date
    Nov 2007
    Posts
    16

    Default Upload File on A5W page

    I am placing a table component on an A5W page. One of the fields is to hold a file that I want to upload from a local drive to the A5W page. On the component side, I cannot designate the field as an upload field. On the A5W side, there is an upload form button to drop on the page, but I have no Idea how to tie the form upload button to the field on my table that I need to hold the file. The bigger problem is that I have no programming knowledge. Is there a way to do that without writing code?

  2. #2
    Volunteer Moderator Steve Wood's Avatar
    Real Name
    Steve Wood
    Join Date
    Nov 2003
    Location
    Bay Area, California
    Posts
    8,843

    Default Re: Upload File on A5W page

    You can easily add an Upload field type to a Grid, but you will have to write code in the A5W page in order to process the upload.

    To add the field, add a calculated field under Query as simple as this Upload="". The variable name is irrelevant an not used anywhere.

    Add the new Upload field to your Grid and in Properties select Freeform. In freeform, add this line:

    Code:
    <input type="file" name="FileToUpload" size=80>
    When your A5W page runs, a variable named FileToUpload will exist and expect a filename.

    I'm going to stop there for now. Please look at the Alpha Help on Uploading a File for instructions on what goes in the A5W page. Its a bit daunting but worth reading to get started understanding what happens to that variable. Plus I am supposed to be doing this for a client right now and I should get to it. I can write it up after I finish that client's work.
    Steve Wood
    Join the ALPHA DEVELOPERS NETWORK
    There is no Cloud. It's just someone else's computer.
    Web - Mobile - Hosting - Products - Frameworks - Developer Resources
    AlphaToGo | IADN (100% Alpha Anywhere Websites)

  3. #3
    Member
    Real Name
    John Burt
    Join Date
    Nov 2007
    Posts
    16

    Default Re: Upload File on A5W page

    Very Cool. I followed your instructions so far and it made a field to open a file dialog. So I select a file and it shows the file path in the field. When I hit submit on the grid, the file does not upload or populate the field on my table. I guess that is where I am suppossed to read the daunting chapter on uploading files. I will start that next. Thanks for your help.

  4. #4
    Volunteer Moderator Steve Wood's Avatar
    Real Name
    Steve Wood
    Join Date
    Nov 2003
    Location
    Bay Area, California
    Posts
    8,843

    Default Re: Upload File on A5W page

    Since I did just finish that work for the client, I will show you what goes in the A5W page. All of this goes at the top of the page, in Source, above all html tags. This is only a portion of the code I used, but it does upload the file. You may also need to rename the file after upload, and that's a bit more code. But maybe daunting is an overstatement once you understand how it works.

    Line 1: Looks to see if they pressed the Save button. Code does not fire until they do. The value inside of the eval_valid function is the HTML name of the "Save" button. I have not tried to do this from the Grids main section and think it would be much more difficult (multiple rows to deal with, rather than just the one record in the Detail).

    You get the name of the Save button by opening up the A5W page in a browser, viewing source and find the name of the Save button. Yours will be different than what I used here. It's normally "componentname_DetailView_Save".

    Line 2: Looks to see if there is a value in that upload field. If not, nothing happens.

    Line 3: Uploads the file to a subfolder named "docs" off of the Document Root (probably c:\A5Webroot\docs). The folder has to exist.

    Code:
    if eval_valid("componentname_DetailView_Save") 
    	IF FileToUpload.filename""
    		file.from_blob("docs\\" + FileToUpload.filename,FileToUpload.data)
    	END IF
    END IF
    ---
    Now, one more thing or the above will do nothing at all. You have to put some code just below the last occurance of a line that looks like this:

    ?x_whatever.Output.Head.CSS_Link

    Example:

    Code:
    ?x_whatever.Output.Head.CSS_Link
    %>
    
    <%a5
    'MY FORM REPLACEMENT CODE
    x_mygrid.Output.Body.DetailView_HTML = stritran(x_mygrid.Output.Body.DetailView_HTML,"method=\"post\"","method=\"post\" enctype=\"multipart/form-data\"")
    %>
    Where you would replace mygrid with the name of your grid component.
    Steve Wood
    Join the ALPHA DEVELOPERS NETWORK
    There is no Cloud. It's just someone else's computer.
    Web - Mobile - Hosting - Products - Frameworks - Developer Resources
    AlphaToGo | IADN (100% Alpha Anywhere Websites)

  5. #5
    Member
    Real Name
    John Burt
    Join Date
    Nov 2007
    Posts
    16

    Default Re: Upload File on A5W page

    Steve, thanks for all of your help. I'm following your instructions and think I am getting close. When I publish the page in IE it shows the top line of code (that you had me paste before the html tag) on the web page. So I do not know if I need to start with a tag or what I am doing wrong. I am posting the code for the first few paragraphs of that page below. Please let me know what to do. Thanks.

    if eval_valid("Reportholder_DetailView_Save")
    IF FileToUpload.filename""
    file.from_blob("docs\\" + FileToUpload.filename,FileToUpload.data)
    END IF
    END IF
    <html>
    <head>

    <%a5

    Delete tmpl_Reportholder
    DIM tmpl_Reportholder as P
    tmpl_Reportholder = a5w_load_component("Reportholder")
    'Following code allows you to override settings in the saved component, and specify the component alias (componentName property).
    'Tip: Keep the componentName property short because this name is used in page URLs, and it will help keep the URLs short.
    'Each component on a page must have a unique alias (componentName property).
    with tmpl_Reportholder
    componentName = "Reportholder"
    end with

Similar Threads

  1. Upload File on A5W page
    By johncburt in forum Application Server Version 8
    Replies: 0
    Last Post: 11-20-2007, 01:36 PM
  2. Copy A5W code object from page to page
    By Steve Wood in forum Archived Wishlist
    Replies: 0
    Last Post: 03-20-2007, 12:43 AM
  3. upload file
    By Sieward in forum Web Application Server v7
    Replies: 1
    Last Post: 02-27-2006, 01:34 PM
  4. Open a a5w page from an a5w page
    By chandran in forum Web Application Server v7
    Replies: 2
    Last Post: 02-02-2006, 04:02 PM
  5. Upload file to web server using web page
    By MIWAYNE in forum Alpha Five Version 6
    Replies: 1
    Last Post: 11-17-2004, 06:30 AM

Bookmarks

Posting Permissions

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