Winsock: HTTP File Upload-VBForums
Page 1 of 2 12 LastLast
Results 1 to 40 of 66

Thread: Winsock: HTTP File Upload

  1. #1

    Thread Starter
    VBA Nutter visualAd's Avatar
    Join Date
    Apr 2002
    Location
    Camden, London Mode: PPI
    Posts
    4,904

    Winsock: HTTP File Upload

    Introduction
    One of the most useful extensions to the HTTP protocol, is the ability to use it to upload files. Although, compared to FTP it is somewhat limited, all that is required to make use of HTTP file uploads is access to a web browser.

    Transferring files using HTTP is generally safer than FTP as the data sent to the server can be carefully scrutinised before the commitment is made to store / use it. For this reason it is ideal in client/server applications which regularly need to transfer data over the Internet.

    The following application, demonstrates how to upload files to a web server using Visual Basic, with the help of the winsock control. In order to add the Winsock Control to your VB6 application, right click on the tool box, select components from the menu and check the box "Microsoft Winsock Control".

    This mimics what a web browser does when you upload a file to a site via a web form.

    A Bit about HTTP

    The Winsock control enables you to establish a connection to another computer using either TCP / UDP and transfer data over that connection. HTTP (Hypertext Transfer Protocol) is used to request and send data to web resources and it is up to the programmer to construct the HTTP request and parse the response.

    The file upload application uses a HTTP POST request to send the file in the form of a multi part HTTP request. This is explained fully in RFC 1867

    Using the Demo Application

    The demo application allows you to enter a URL and choose the file which you wish to upload. You must give the file a name and an MIME type; a list of MIME types for particular file extensions can be found here.

    Pressing the upload button sends the HTTP request containing the data from the file which you have chosen.

    Like I mentioned earlier HTTP file uploads are useful in client / server applications. So, I have made a script which will take file uploads to demonstrate how the application works, it also has a web interface:

    http://adam.codedv.com/examples/post_dump.php

    The files which have been uploaded can be found here, it is clear that there is no conceivable difference between files uploaded via VB and via a web browser. The means in which the server gets the data is transparent.

    Attached Images Attached Images  
    Attached Files Attached Files
    PHP || MySql || Apache || Get Firefox || OpenOffice.org || Click || Slap ILMV || 1337 c0d || GotoMyPc For FREE! Part 1, Part 2

    | PHP Session --> Database Handler * Custom Error Handler * Installing PHP * HTML Form Handler * PHP 5 OOP * Using XML * Ajax * Xslt | VB6 Winsock - HTTP POST / GET * Winsock - HTTP File Upload

    Latest quote: crptcblade - VB6 executables can't be decompiled, only disassembled. And the disassembled code is even less useful than I am.

    Random VisualAd: Blog - Latest Post: When the Internet becomes Electricity!!


    Spread happiness and joy. Rate good posts.

  2. #2
    New Member
    Join Date
    Jun 2005
    Posts
    2

    Re: Winsock: HTTP File Upload

    plz send to me the (post_dump.php) file to put it in my site and try it
    send it to
    hanysabra@hotmail.com

  3. #3
    Super Moderator Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,335

    Re: Winsock: HTTP File Upload

    Quote Originally Posted by sabricka
    plz send to me the (post_dump.php) file to put it in my site and try it
    send it to
    First, welcome to the forums.

    Second, you should never, ever put your email address in any open forum post anywhere. It is very easy for spam bots to pick that up.

    If you wish to let one of our members know what your email address, please use our internal private messenging system. Thanks.
    Last edited by Hack; Jun 13th, 2005 at 12:03 PM.
    Please use [Code]your code goes in here[/Code] tags when posting code.
    When you have received an answer to your question, please mark it as resolved using the Thread Tools menu.
    Before posting your question, did you look here?
    Got a question on Linux? Visit our Linux sister site.
    I dont answer coding questions via PM or EMail. Please post a thread in the appropriate forum section.

    Creating A Wizard In VB.NET
    Paging A Recordset
    What is wrong with using On Error Resume Next
    Good Article: Language Enhancements In Visual Basic 2010
    Upgrading VB6 Code To VB.NET
    Microsoft MVP 2005/2006/2007/2008/2009/2010/2011/2012/Defrocked

  4. #4

    Thread Starter
    VBA Nutter visualAd's Avatar
    Join Date
    Apr 2002
    Location
    Camden, London Mode: PPI
    Posts
    4,904

    Re: Winsock: HTTP File Upload

    Everyone seems to want the source code for the PHP files. So, here they are.

    The post_dump.php file simply loops through all the posted variables and files and displays information on them. It saves the files in another directory, so to use it you need to create two directories:

    uploaded_files
    uploaded_files/files

    post_dump.php
    PHP Code:
    <?php
        
    /* check for and loop through uploaded files */
        
    foreach ($_FILES as $name => $info) {
            
    /* chekc the file has a valid name */
            
    if (($info['name'] != 'ht.access' &&
                
    substr($info['name'], 0,1) != '.' &&
                
    $info['name'] != 'allowed_files')) {

                
    /* attempt to move the file to the uploaded_files directory */
                
    if (@move_uploaded_file($info['tmp_name'], "uploaded_files/files/{$info['name']}")) {
                    
    /* get the contenst of the array of files */
                    
    $file_arrays = @unserialize(@file_get_contents('uploaded_files/allowed_files'));        
        
                    
    /* if there are more already 5 files, remove the oldest item fomr the array
                     * and delete it 
                     */
                    
    if (count(@$file_arrays['files']) == 5) {
                        
    $name array_shift($file_arrays['files']);
                
                        unset(
    $file_arrays['types'][$name]);
                        @
    unlink('uploaded_files/files/' $name);
                    }

                    
    /* add the new item to the arrays */
                    
    $file_arrays['files'][] = $info['name'];
                    
    $file_arrays['types'][$info['name']] = $info['type'];

                    
    /* serialize the array and write it back to the file */
                    
    if ($fhwnd = @fopen('uploaded_files/allowed_files''wb+')) {
                        
    fwrite($fhwndserialize($file_arrays));
                        
    fclose($fhwnd);
                    }
                }          
            }   
        }
    ?>
    <html>
        <head>
            <title>Form Post Dump</title>
        </head>
        <body>
            <?php if ($_POST): ?>
                <p>You submitted the following POST variables with the following names:</p>
                <ul><?php foreach($_POST as $name => $var) : ?>
                    <li><?php echo(htmlspecialchars($name)) ?> = <?php echo(htmlspecialchars($var)) ?></li>
                <?php endforeach; ?></ul>
            <?php endif; ?>
            <?php if ($_GET): ?>
                <p>You submitted the following fariables with the query string:</p>
                <ul><?php foreach($_GET as $name => $var) : ?>
                    <li><?php echo(htmlspecialchars($name)) ?> = <?php echo(htmlspecialchars($var)) ?></li>
                <?php endforeach; ?></ul>
            <?php endif; ?>
            <?php if ($_FILES): ?>
                <p>You submitted the following FILES:</p>
                <ul><?php foreach($_FILES as $name => $info): ?>
                    <li>File name: <?php echo(htmlspecialchars($name)) ?>
                <ul>
                    <li>Client file name: <?php echo(htmlspecialchars($info['name'])) ?></li>
                    <li>File MIME type: <?php echo(htmlspecialchars($info['type'])) ?></li>
                    <li>File size: <?php echo(htmlspecialchars($info['size'])) ?></li>
                    <li>Download link: <a href="uploaded_files.php?file=<?php echo(htmlspecialchars($info['name'])) ?>"><?php echo(htmlspecialchars($info['name'])) ?></a></li>
                </ul>
                </li>
            </ul>
                <?php endforeach; ?></ul>
            <?php endif; ?>
            <form enctype="multipart/form-data" action="<?php echo($_SERVER['PHP_SELF']) ?>" method="post">
                <p>Variable1: <input type="text" name="variable1" /></p>
                <p>Variable2: <input type="text" name="variable2" /></p>
                <p>Variable3: <input type="text" name="variable3" /></p>
                <p>File: <input type="file" name="file1" /></p>
                <p><input type="submit" value="Post" /></p>
            </form>
        </body>
    </html>
    Direct link to the source code: http://adam.codedv.com/examples/post_dump.phps

    The uploaded_files.php file, displays or allows the user to download last 5 uploaded files.

    uploaded_files.php
    PHP Code:
    <?php
        
    /* load the file containg the list of uploaded files in to an array */
        
    $file_arrays = @unserialize(@file_get_contents('uploaded_files/allowed_files'));

        
    /* check the data was loaded successfully - if not, create an empty array */
        
    if (!is_array($file_arrays)) {
            
    $file_arrays = array('files' => array(), 'types' => array());
        }

        
    /* check for the existance of a file variable in the queery string
         * if its there, this contains the name of the file to be downlaoded
         */
        
    if (isset($_GET['file'])) {
            
    $file $_GET['file'];
            
            
    /* check the file is in the array retrieved from the file */
            
    if (in_array($file, @$file_arrays['files'])) {
                
    /* get the Content-Type of the file */
                
    header('Content-Type: ' $file_arrays['types'][$file]);
                
    header('Content-Disposition: attachment; filename="' $file '"');

                
    /* send the file */
                
    @readfile("uploaded_files/files/$file");
                exit;
            }
        }
    ?>
    <html>
        <head>
            <title>Uploaded Files</title>
        </head>
        <body>
            <h3>Recently Uploaded Files</h3>
            <ul>
                <?php foreach($file_arrays['files'] as $file): ?>
                    <li><a href="<?php echo($_SERVER['PHP_SELF'] . '?file=' htmlspecialchars($file))?>">
                        <?php echo(htmlspecialchars($file)) ?></a>
                    </li>
                <?php endforeach; ?>
            </ul>
        </body>
    </html>
    Direct link to the source code: http://adam.codedv.com/examples/uploaded_files.phps
    Last edited by visualAd; Jun 13th, 2005 at 09:22 AM.
    PHP || MySql || Apache || Get Firefox || OpenOffice.org || Click || Slap ILMV || 1337 c0d || GotoMyPc For FREE! Part 1, Part 2

    | PHP Session --> Database Handler * Custom Error Handler * Installing PHP * HTML Form Handler * PHP 5 OOP * Using XML * Ajax * Xslt | VB6 Winsock - HTTP POST / GET * Winsock - HTTP File Upload

    Latest quote: crptcblade - VB6 executables can't be decompiled, only disassembled. And the disassembled code is even less useful than I am.

    Random VisualAd: Blog - Latest Post: When the Internet becomes Electricity!!


    Spread happiness and joy. Rate good posts.

  5. #5
    New Member
    Join Date
    Jun 2005
    Posts
    2

    Re: Winsock: HTTP File Upload

    thank you too match and many thanks to this great fourm

  6. #6
    New Member
    Join Date
    Jun 2005
    Posts
    4

    Resolved [RESOLVED] Re: Winsock: HTTP File Upload

    This programs are working some how okey, but when I try to use the documents (JPG pictures or any other) online (meaning on a web page or by direct access to it from a web folder,) It just doesn't work. I can not use the files online. Why? Is there any whay to do it, or fix it. I have being trying all kinds of things: change mime type, etc. But still nothing. I will apreciate any help.
    Last edited by joechez; Jun 26th, 2005 at 09:52 AM.

  7. #7

    Thread Starter
    VBA Nutter visualAd's Avatar
    Join Date
    Apr 2002
    Location
    Camden, London Mode: PPI
    Posts
    4,904

    Re: Winsock: HTTP File Upload

    Can you clarify what the problem is? - Is it with the server scripts or the example program? Do you get any error messages or is the file just messed up?
    PHP || MySql || Apache || Get Firefox || OpenOffice.org || Click || Slap ILMV || 1337 c0d || GotoMyPc For FREE! Part 1, Part 2

    | PHP Session --> Database Handler * Custom Error Handler * Installing PHP * HTML Form Handler * PHP 5 OOP * Using XML * Ajax * Xslt | VB6 Winsock - HTTP POST / GET * Winsock - HTTP File Upload

    Latest quote: crptcblade - VB6 executables can't be decompiled, only disassembled. And the disassembled code is even less useful than I am.

    Random VisualAd: Blog - Latest Post: When the Internet becomes Electricity!!


    Spread happiness and joy. Rate good posts.

  8. #8
    New Member
    Join Date
    Jun 2005
    Posts
    4

    Re: Winsock: HTTP File Upload

    I just want to use the uploaded pictures on my website, but they just don't work. If I upload manually using ftp they work just fine. But if I use the script, they don't. Then using the script, I uploaded some pictures (to try out) and downloaded them using ftp. Then uploaded them againg using ftp, and they didn't show up. So, something happend with the pictures using the script. I try other documents also with the same results.

  9. #9

    Thread Starter
    VBA Nutter visualAd's Avatar
    Join Date
    Apr 2002
    Location
    Camden, London Mode: PPI
    Posts
    4,904

    Re: Winsock: HTTP File Upload

    What errors are you getting? And have you created the correct directories to place the uploaded files in?
    PHP || MySql || Apache || Get Firefox || OpenOffice.org || Click || Slap ILMV || 1337 c0d || GotoMyPc For FREE! Part 1, Part 2

    | PHP Session --> Database Handler * Custom Error Handler * Installing PHP * HTML Form Handler * PHP 5 OOP * Using XML * Ajax * Xslt | VB6 Winsock - HTTP POST / GET * Winsock - HTTP File Upload

    Latest quote: crptcblade - VB6 executables can't be decompiled, only disassembled. And the disassembled code is even less useful than I am.

    Random VisualAd: Blog - Latest Post: When the Internet becomes Electricity!!


    Spread happiness and joy. Rate good posts.

  10. #10
    New Member
    Join Date
    Jun 2005
    Posts
    4

    Re: Winsock: HTTP File Upload

    Yes! I have created the needed folders. As I said the script is working. I can upload and download files. But the files get corrupted or something because after doing an upload, they just don't work on regular web pages. I think the attributes of the files are changing or something.

  11. #11
    New Member
    Join Date
    Jun 2005
    Posts
    4

    Re: Winsock: HTTP File Upload

    Yeep! The files work okey just changing the attributes to public read and to group read. Still looking forward to transffer variables at the same time using VB6.

  12. #12
    New Member
    Join Date
    Apr 2005
    Posts
    6

    Re: Winsock: HTTP File Upload

    Hi,


    The above example wont work with https site.Pls let me know the solution.

    Thanks
    Harish

  13. #13

    Thread Starter
    VBA Nutter visualAd's Avatar
    Join Date
    Apr 2002
    Location
    Camden, London Mode: PPI
    Posts
    4,904

    Re: Winsock: HTTP File Upload

    HTTPs is HTTP tunneled through SSL. Unfortunatly this is vastly more complicated than a standard unencrypted HTTP connection and somthing which I haven't got the time or the knowledge to do at the moment.
    PHP || MySql || Apache || Get Firefox || OpenOffice.org || Click || Slap ILMV || 1337 c0d || GotoMyPc For FREE! Part 1, Part 2

    | PHP Session --> Database Handler * Custom Error Handler * Installing PHP * HTML Form Handler * PHP 5 OOP * Using XML * Ajax * Xslt | VB6 Winsock - HTTP POST / GET * Winsock - HTTP File Upload

    Latest quote: crptcblade - VB6 executables can't be decompiled, only disassembled. And the disassembled code is even less useful than I am.

    Random VisualAd: Blog - Latest Post: When the Internet becomes Electricity!!


    Spread happiness and joy. Rate good posts.

  14. #14
    New Member
    Join Date
    Dec 2005
    Posts
    1

    Re: Winsock: HTTP File Upload

    Hi All,

    Even i am struggling with uploading files for https sites using vb 6.0.
    If anybody gets the solution don't forget to post it here..Also i am looking for this solution very urgently...so pls pls post it asap.

    Thanks in advanc
    svhk

  15. #15
    New Member
    Join Date
    Dec 2005
    Posts
    1

    Re: Winsock: HTTP File Upload

    Hi everyone,

    The PHP and VB6 code posted here works really well.

    I was just wondering if it would be possible to generalize it to do what I would call "custom folders" (on the server).

    I would like to be able to upload just one licence file to a few dozen different folders (one per client). The version of the file is different for each folder.

    It would nice to be able to put a loop around the VB6 upload code to make this happen.

    But I don't know enough about the methodology used in the current PHP and VB6 code to do this.

    Any suggestions would be most welcome.

    Regards, Leigh

  16. #16
    New Member
    Join Date
    Apr 2006
    Posts
    1

    Re: Winsock: HTTP File Upload

    QUESTION:

    I am connected to Internet Via Proxy. How can I make this sample work?
    If I have a direct connection, everything works well.

    Through proxy, I am getting this error: 'Valid name, no data record of requested type' (Code 11004) Need advice..

    Thank you all.

  17. #17
    New Member
    Join Date
    May 2006
    Posts
    2

    Re: Winsock: HTTP File Upload

    anyone here can upload jpg, doc, zip... by this program? I have tried many time and can't success...
    But I found that there are no problem when uploading plain text file(txt).

  18. #18

    Thread Starter
    VBA Nutter visualAd's Avatar
    Join Date
    Apr 2002
    Location
    Camden, London Mode: PPI
    Posts
    4,904

    Re: Winsock: HTTP File Upload

    It works fine for me. Do you get any errors? And are you sending the right MIME type?
    Last edited by visualAd; May 7th, 2006 at 09:44 AM.
    PHP || MySql || Apache || Get Firefox || OpenOffice.org || Click || Slap ILMV || 1337 c0d || GotoMyPc For FREE! Part 1, Part 2

    | PHP Session --> Database Handler * Custom Error Handler * Installing PHP * HTML Form Handler * PHP 5 OOP * Using XML * Ajax * Xslt | VB6 Winsock - HTTP POST / GET * Winsock - HTTP File Upload

    Latest quote: crptcblade - VB6 executables can't be decompiled, only disassembled. And the disassembled code is even less useful than I am.

    Random VisualAd: Blog - Latest Post: When the Internet becomes Electricity!!


    Spread happiness and joy. Rate good posts.

  19. #19
    New Member
    Join Date
    May 2006
    Posts
    2

    Re: Winsock: HTTP File Upload

    Thank for your reply and your great program first!!

    After many times of try and error, I found that it can upload jpg under ENGLISH WinXP, but not in CHINESE WinXP.

    for CHINESE WinXP:
    There are no error when uploading jpg file, but when I try to download the jpg file from server, I found that the content of jpg is changed and it can't be opened again. May be it is becasue of the encoding problems?

  20. #20
    New Member
    Join Date
    Jul 2006
    Location
    San Salvador, El Salvador
    Posts
    2

    Thumbs up Re: Winsock: HTTP File Upload

    Hi!, in first place let me thank you for share your code visualAd, second a few questions about it:

    1)Could your code work with "multipart/form-data" header type?
    2)Wich is the max size of the file that can effectively be send?, despiting the servers limitations.
    3)How necessary is to do it with winsock.ocx?, it's difficult to do it through winsocks APIs?, does need winsock.ocx be packed along the aplication?
    4)Could your code be reproducible with Wininet APIs?

    Thanks in advance. Glad to see that someone is sharing this kind of hard to find but high usable code.

  21. #21

    Thread Starter
    VBA Nutter visualAd's Avatar
    Join Date
    Apr 2002
    Location
    Camden, London Mode: PPI
    Posts
    4,904

    Re: Winsock: HTTP File Upload

    1)Could your code work with "multipart/form-data" header type?
    What do you mean? It uses the multipart/form-data header in the HTTP request and sends the HTTP request as a multipart document.

    2)Wich is the max size of the file that can effectively be send?, despiting the servers limitations.
    I am not sure probably the size of a VB string 64k. However, with anything bigger, VB should use swap or other mechanisms to handle the string. I am no VB guru so cannot say for sure.

    3)How necessary is to do it with winsock.ocx?, it's difficult to do it through winsocks APIs?, does need winsock.ocx be packed along the aplication?
    In theory the ocx should be included. If not, you need to ensure that the control is installed on the OS you are running the program on and hope that if it is installed the version is compatible withh the one you've used.

    Winsock is included by default from windows 98+, so I would imagain you'd be quite safe.

    4)Could your code be reproducible with Wininet APIs?
    I should hope so, as this is exaclty what the Winsock control is a wrapper for
    PHP || MySql || Apache || Get Firefox || OpenOffice.org || Click || Slap ILMV || 1337 c0d || GotoMyPc For FREE! Part 1, Part 2

    | PHP Session --> Database Handler * Custom Error Handler * Installing PHP * HTML Form Handler * PHP 5 OOP * Using XML * Ajax * Xslt | VB6 Winsock - HTTP POST / GET * Winsock - HTTP File Upload

    Latest quote: crptcblade - VB6 executables can't be decompiled, only disassembled. And the disassembled code is even less useful than I am.

    Random VisualAd: Blog - Latest Post: When the Internet becomes Electricity!!


    Spread happiness and joy. Rate good posts.

  22. #22
    New Member
    Join Date
    Jul 2006
    Location
    San Salvador, El Salvador
    Posts
    2

    Re: Winsock: HTTP File Upload

    Quote Originally Posted by visualAd
    What do you mean? It uses the multipart/form-data header in the HTTP request and sends the HTTP request as a multipart document.
    Yes sorry, just notice that in the code, I got confused when see this:

    VB Code:
    1. ' Content-Disposition: form-data; name="UploadName"; filename="FileName"

    Later I see this:
    VB Code:
    1. ' Content-Type: multipart-form-data, boundary=boundary

    Quote Originally Posted by visualAd
    I am not sure probably the size of a VB string 64k. However, with anything bigger, VB should use swap or other mechanisms to handle the string. I am no VB guru so cannot say for sure.in the HTTP request and sends the HTTP request as a multipart document.
    Ok, lets say I want to send a 500KBs file, supossing that limit is 64KB, I should use a string class or there's a way to send chunks of data at time?

    Quote Originally Posted by visualAd
    In theory the ocx should be included. If not, you need to ensure that the control is installed on the OS you are running the program on and hope that if it is installed the version is compatible withh the one you've used.
    Winsock is included by default from windows 98+, so I would imagain you'd be quite safe.
    So it will be ok for most cases to do it with winsock.ocx rather than directly calls to winsock.dll?

    Quote Originally Posted by visualAd
    I should hope so, as this is exaclty what the Winsock control is a wrapper for
    Thanks.

  23. #23
    New Member
    Join Date
    Jul 2006
    Posts
    1

    What if

    What if I need to send more data in the form. Like two other input type="text" in the same form to autenticate the user that is sending the file??? Please help.

  24. #24

    Thread Starter
    VBA Nutter visualAd's Avatar
    Join Date
    Apr 2002
    Location
    Camden, London Mode: PPI
    Posts
    4,904

    Re: Winsock: HTTP File Upload

    You need to encode each variable as a part in the HTTP request. I.e:
    Code:
    --BOUNDARY
    Content-Disposition: form-data; name="var1"
    
    value1
    --BOUNDARY
    Content-Disposition: form-data; name="var2"
    
    value2
    --BOUNDARY
    Content-Disposition: form-data; name="file"; filename="file.txt"
    Content-Type: text/plain
    
    File text.
    --BOUNDARY--
    PHP || MySql || Apache || Get Firefox || OpenOffice.org || Click || Slap ILMV || 1337 c0d || GotoMyPc For FREE! Part 1, Part 2

    | PHP Session --> Database Handler * Custom Error Handler * Installing PHP * HTML Form Handler * PHP 5 OOP * Using XML * Ajax * Xslt | VB6 Winsock - HTTP POST / GET * Winsock - HTTP File Upload

    Latest quote: crptcblade - VB6 executables can't be decompiled, only disassembled. And the disassembled code is even less useful than I am.

    Random VisualAd: Blog - Latest Post: When the Internet becomes Electricity!!


    Spread happiness and joy. Rate good posts.

  25. #25

    Thread Starter
    VBA Nutter visualAd's Avatar
    Join Date
    Apr 2002
    Location
    Camden, London Mode: PPI
    Posts
    4,904

    Re: Winsock: HTTP File Upload

    I'll have a look at modifying the app to include other variables, it is easy enough to modify by yourself however. Also, have a look at the demo app for sending GET/POST HTTP requests.
    PHP || MySql || Apache || Get Firefox || OpenOffice.org || Click || Slap ILMV || 1337 c0d || GotoMyPc For FREE! Part 1, Part 2

    | PHP Session --> Database Handler * Custom Error Handler * Installing PHP * HTML Form Handler * PHP 5 OOP * Using XML * Ajax * Xslt | VB6 Winsock - HTTP POST / GET * Winsock - HTTP File Upload

    Latest quote: crptcblade - VB6 executables can't be decompiled, only disassembled. And the disassembled code is even less useful than I am.

    Random VisualAd: Blog - Latest Post: When the Internet becomes Electricity!!


    Spread happiness and joy. Rate good posts.

  26. #26
    Junior Member hellilyntax's Avatar
    Join Date
    Jun 2006
    Location
    Kedah, Malaysia
    Posts
    28

    Re: Winsock: HTTP File Upload

    pls somebody..
    why did i get this error msg..

    HTTP/1.1 401 Access Denied
    Server: Microsoft-IIS/5.1
    Date: Mon, 19 Jun 2006 18:00:32 GMT
    WWW-Authenticate: Negotiate
    WWW-Authenticate: NTLM
    Content-Length: 24
    Content-Type: text/html

    Error: Access is Denied.

  27. #27

    Thread Starter
    VBA Nutter visualAd's Avatar
    Join Date
    Apr 2002
    Location
    Camden, London Mode: PPI
    Posts
    4,904

    Re: Winsock: HTTP File Upload

    You need to authenticate yourself using NTLM (Microsoft Windows NT LAN Manager) authentication. It is possible to do this in VB but involves a lot of byte shifting and code.
    PHP || MySql || Apache || Get Firefox || OpenOffice.org || Click || Slap ILMV || 1337 c0d || GotoMyPc For FREE! Part 1, Part 2

    | PHP Session --> Database Handler * Custom Error Handler * Installing PHP * HTML Form Handler * PHP 5 OOP * Using XML * Ajax * Xslt | VB6 Winsock - HTTP POST / GET * Winsock - HTTP File Upload

    Latest quote: crptcblade - VB6 executables can't be decompiled, only disassembled. And the disassembled code is even less useful than I am.

    Random VisualAd: Blog - Latest Post: When the Internet becomes Electricity!!


    Spread happiness and joy. Rate good posts.

  28. #28
    Junior Member hellilyntax's Avatar
    Join Date
    Jun 2006
    Location
    Kedah, Malaysia
    Posts
    28

    Re: Winsock: HTTP File Upload

    thanks 4 ur reply visualAd,
    pls gimme more detail, how to do so..in policy setting?
    im using winxp as webserver(just for development)..

    im going to host my webserver at hosting company...
    what do i need to tell them to do?

    ill buy u a pasta then..hehe..

  29. #29

    Thread Starter
    VBA Nutter visualAd's Avatar
    Join Date
    Apr 2002
    Location
    Camden, London Mode: PPI
    Posts
    4,904

    Re: Winsock: HTTP File Upload

    Quote Originally Posted by hellilyntax
    thanks 4 ur reply visualAd,
    pls gimme more detail, how to do so..in policy setting?
    im using winxp as webserver(just for development)..

    im going to host my webserver at hosting company...
    what do i need to tell them to do?

    ill buy u a pasta then..hehe..
    NTLM is a challenge response protocol. That means the client needs to make a connection containing a challenge and the server makes the response. No user name and password are ever transmitted to the server - the authentication takes place with the domain controller.

    Like I say. I have never written an NTLM authenticator in VB and I do not plan to either. That doesn't mean the its not possible, just that its a complex and time consuming task.

    If you want to do it yourself here is a detailed specification.

    http://curl.haxx.se/rfc/ntlm.html
    PHP || MySql || Apache || Get Firefox || OpenOffice.org || Click || Slap ILMV || 1337 c0d || GotoMyPc For FREE! Part 1, Part 2

    | PHP Session --> Database Handler * Custom Error Handler * Installing PHP * HTML Form Handler * PHP 5 OOP * Using XML * Ajax * Xslt | VB6 Winsock - HTTP POST / GET * Winsock - HTTP File Upload

    Latest quote: crptcblade - VB6 executables can't be decompiled, only disassembled. And the disassembled code is even less useful than I am.

    Random VisualAd: Blog - Latest Post: When the Internet becomes Electricity!!


    Spread happiness and joy. Rate good posts.

  30. #30
    Junior Member hellilyntax's Avatar
    Join Date
    Jun 2006
    Location
    Kedah, Malaysia
    Posts
    28

    Re: Winsock: HTTP File Upload

    thanks a lot visualAd,
    it sound quite hard for that coding...
    me either didnt plan to do so...hehe...

    im better choose another solution...
    im planning to update my sql server directly from my vb local client instead of upload the file then update at the server.

    which one is better in terms of reliability?

  31. #31
    New Member
    Join Date
    Aug 2006
    Posts
    1

    Re: Winsock: HTTP File Upload

    Hi All,
    problem
    look at the picture
    Attached Images Attached Images  

  32. #32

    Thread Starter
    VBA Nutter visualAd's Avatar
    Join Date
    Apr 2002
    Location
    Camden, London Mode: PPI
    Posts
    4,904

    Re: Winsock: HTTP File Upload

    That is an HTTP error. It means you don't have permission to access the file.
    PHP || MySql || Apache || Get Firefox || OpenOffice.org || Click || Slap ILMV || 1337 c0d || GotoMyPc For FREE! Part 1, Part 2

    | PHP Session --> Database Handler * Custom Error Handler * Installing PHP * HTML Form Handler * PHP 5 OOP * Using XML * Ajax * Xslt | VB6 Winsock - HTTP POST / GET * Winsock - HTTP File Upload

    Latest quote: crptcblade - VB6 executables can't be decompiled, only disassembled. And the disassembled code is even less useful than I am.

    Random VisualAd: Blog - Latest Post: When the Internet becomes Electricity!!


    Spread happiness and joy. Rate good posts.

  33. #33
    New Member
    Join Date
    Jun 2006
    Posts
    4

    Re: Winsock: HTTP File Upload

    First of all, I want to thank you for the code. I've been using it for a while and it works great.

    Now for my question. Has anyone used a progress bar with the winsock control for uploading files? I'm new to progress bars and want to add one to this code for my program users. Any suggestions, refrences or code would be greatly appreciated.

    Thanks in advance

  34. #34
    New Member
    Join Date
    Nov 2006
    Posts
    1

    Re: Winsock: HTTP File Upload

    This is fantastic.

    Has anyone created an ASP version of the PHP code ?

    Thank-you.

    Juls

  35. #35
    PoorPoster iPrank's Avatar
    Join Date
    Oct 2005
    Location
    In a black hole
    Posts
    2,727

    Re: Winsock: HTTP File Upload

    Hey Visual,
    any idea how to modify this code for imagesack.us or similar sites ? These sites redirects to another page (which contains the new links) after uploading.

    I tried to upload google2.gif to imagesack usin your code and got this:

    Upload URL:
    Code:
    tried these two:
    http://www.imageshack.us/transload.php
    http://imageshack.us/ie.php
    HTTP Request:
    Code:
    POST /transload.php? HTTP/1.0
    Host: www.imageshack.us
    Content-Type: multipart/form-data, boundary=tf63uHQ4SWyMnYsVco1QyHEi5qlB08uv
    Content-Length: 1739
    
    --tf63uHQ4SWyMnYsVco1QyHEi5qlB08uv
    Content-Disposition: form-data; name="file"; filename="google2.gif"
    Content-Type: application/octet-stream
    
    GIF89a4
    HTTP Response:
    Code:
    HTTP/1.0 302 Found
    Connection: close
    X-Powered-By: PHP/4.4.2
    location: http://www.imageshack.us/
    Content-type: text/html
    Content-Length: 0
    Date: Mon, 18 Dec 2006 19:33:19 GMT
    Server: lighttpd/1.4.8
    1. How do I get the new links of uploade file ?
    2. What changes need to be made for registered users ?
    (Imagesack doesn't allow image deletion for unregistered users)
    Last edited by iPrank; Dec 18th, 2006 at 01:55 PM.
    Usefull VBF Threads/Posts I Found . My flickr page .
    "I love being married. It's so great to find that one special person you want to annoy for the rest of your life." - Rita Rudner


  36. #36
    Frenzied Member litlewiki's Avatar
    Join Date
    Dec 2005
    Location
    Zeta Reticuli Distro:Ubuntu Fiesty
    Posts
    1,162

    Re: Winsock: HTTP File Upload

    Try the one from vbip.com.It detects redirects.I'm not sure though if this is what you asked for:
    http://www.vbip.com/winsock/winsock_http_07_01.asp
    __________________
    ________________0ооо___
    ___ооо0________(___)____
    __(___)_________) _/_____
    ___\_ (_________(_/______
    ____\_)_________________

  37. #37
    PoorPoster iPrank's Avatar
    Join Date
    Oct 2005
    Location
    In a black hole
    Posts
    2,727

    Re: Winsock: HTTP File Upload

    Sorry for the confusion. I shouldn't have said 'redirection'.
    I tried to mean, when you finish uploading files in imagesack (or YahooMail) they opens a new page that contains URL of the newly uploaded file. (In case of YMail, it is the 'finish attatching file and continue to message' page.)

    Getting the HTML of this 'uploading-finished-and-here-is-your-URL' page is necessary. Without it I can't get URL of my own images.

    When I tried to mix Visual's and VBIP's code, I got this as 'new URL'.
    Code:
    http://www.imageshack.us/2 Found
    and there is still my second question. How to login to that site with Winsock and upload to that account. (OK, I can use Webbrowser control, but that would be slow.)

    [I need this 'cause I want to make a smily collection app like the one Static was making, but want to store the images in ImageSack for easier sharing]
    Last edited by iPrank; Dec 18th, 2006 at 10:53 PM.
    Usefull VBF Threads/Posts I Found . My flickr page .
    "I love being married. It's so great to find that one special person you want to annoy for the rest of your life." - Rita Rudner


  38. #38
    Frenzied Member litlewiki's Avatar
    Join Date
    Dec 2005
    Location
    Zeta Reticuli Distro:Ubuntu Fiesty
    Posts
    1,162

    Re: Winsock: HTTP File Upload

    You need to have cookies enabled for that and also it returns a 302(temporarily moved) which means it is not handling the redirects(not exactly redirects but kinda) properly.

    I don't how far i can help you out but i can suggest these:

    1.Get live http headers extension for Firefox.:
    http://livehttpheaders.mozdev.org/

    2.Check out the way things work in the background: Here is my output:

    Code:
    http://reg.imageshack.us/setlogin.ph...051795891XXXXX
    GET /setlogin.php?login=eef5cc5e36b051795891XXXXX HTTP/1.1
    Host: reg.imageshack.us
    User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1) Gecko/20061010 Firefox/2.0
    Accept: text/xml,application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5
    Accept-Language: en-us,en;q=0.5
    Accept-Encoding: gzip,deflate
    Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7
    Keep-Alive: 300
    Connection: keep-alive
    
    HTTP/1.x 302 Found
    Connection: close
    X-Powered-By: PHP/5.1.2
    Location: http://dev.imageshack.us/setlogin.ph...xxxxxxxxx&xml=
    Content-Type: text/html
    Content-Length: 0
    Date: Tue, 19 Dec 2006 07:13:18 GMT
    Server: lighttpd/1.4.8
    ----------------------------------------------------------
    http://dev.imageshack.us/setlogin.ph...xxxxxxxxx&xml=
    
    GET /setlogin.php?login=eef5cc5e36b051795891xxxxxxxxx&xml= HTTP/1.1
    Host: dev.imageshack.us
    User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1) Gecko/20061010 Firefox/2.0
    Accept: text/xml,application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5
    Accept-Language: en-us,en;q=0.5
    Accept-Encoding: gzip,deflate
    Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7
    Keep-Alive: 300
    Connection: keep-alive
    
    HTTP/1.x 302 Found
    Date: Tue, 19 Dec 2006 07:09:08 GMT
    Server: Apache/2.0.52 (CentOS)
    X-Powered-By: PHP/4.3.9
    Set-Cookie: myid=3733953; expires=Fri, 14-Dec-2007 07:09:08 GMT; path=/; domain=.imageshack.us
    Set-Cookie: myimages=eef5cc5e36b051795891xxxxxxf3; expires=Fri, 14-Dec-2007 07:09:08 GMT; path=/; domain=.imageshack.us
    Location: http://reg.imageshack.us/v_images.php
    Content-Length: 0
    Connection: close
    Content-Type: text/html; charset=UTF-8
    ----------------------------------------------------------
    http://reg.imageshack.us/v_images.php
    
    GET /v_images.php HTTP/1.1
    Host: reg.imageshack.us
    User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1) Gecko/20061010 Firefox/2.0
    Accept: text/xml,application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5
    Accept-Language: en-us,en;q=0.5
    Accept-Encoding: gzip,deflate
    Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7
    Keep-Alive: 300
    Connection: keep-alive
    Cookie: myid=3733953; myimages=eef5cc5e36b051795891xxxxx90f3
    
    HTTP/1.x 200 OK
    Connection: close
    X-Powered-By: PHP/5.1.2
    Set-Cookie: myimages=eef5cc5e36b051795891xxxxxxxx; expires=Fri, 14-Dec-2007 07:13:21 GMT; domain=.imageshack.us
    Content-Type: text/html
    Date: Tue, 19 Dec 2006 07:13:21 GMT
    Server: lighttpd/1.4.8
    Transfer-Encoding: chunked
    ----------------------------------------------------------
    3.Then use these api functions to set and get cookies accordingly.
    http://support.microsoft.com/kb/q196062/

    I suggest you use inet control for this or the class module from vbip.com .

    If needed try the user agent extension and modify headers extension to play around with headers.
    __________________
    ________________0ооо___
    ___ооо0________(___)____
    __(___)_________) _/_____
    ___\_ (_________(_/______
    ____\_)_________________

  39. #39
    Junior Member
    Join Date
    Feb 2007
    Posts
    16

    Re: Winsock: HTTP File Upload

    Thanks for such a wonderful script. How do I cite you as a credit for when I use it?

    I got this error:
    HTTP/1.1 406 Not Acceptable
    Date: Thu, 08 Feb 2007 19:12:41 GMT
    Server: Apache/1.3.37 (Unix) mod_auth_passthrough/1.8 mod_log_bytes/1.2 mod_bwlimited/1.4 FrontPage/5.0.2.2635.SR1.2 mod_ssl/2.8.28 OpenSSL/0.9.7a PHP-CGI/0.1b
    Connection: close
    Content-Type: text/html; charset=iso-8859-1

    <!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">
    <HTML><HEAD>
    <TITLE>406 Not Acceptable</TITLE>
    </HEAD><BODY>
    <H1>Not Acceptable</H1>
    An appropriate representation of the requested resource /politicstestresults/post_dump.php could not be found on this server.<P>
    <HR>
    <ADDRESS>Apache/1.3.37 Server at www.kelceycoe.com Port 80</ADDRESS>
    </BODY></HTML>

    I've uploaded the files to my upload directory as shown, and chomodded the directory and php files as 777. Is that right or am I doing something way wrong? Thanks.
    Last edited by kelceycoe; Feb 8th, 2007 at 01:14 PM.

  40. #40
    New Member
    Join Date
    Aug 2006
    Location
    Mumbai
    Posts
    7

    Re: Winsock: HTTP File Upload

    Guys,

    Me trying to upload file using VB HTTP Post method. Can successfully upload the files when my client machine is English OS . However , the problem occurs when am trying to upload the files from Chinese OS. It seems that the file uploaded is getting corrupted and could not be opened in correct format. This is applicable for binary files. The text files could be uploaded successfully.
    I have tried setting content-type, charset,codepage etc properties to assemble the body.

    Can anyone help me ? Its urgent ....Hope to find some VB GURU in this group.HELP !

    Thanks in advance,
    Ashish.0.










    Quote Originally Posted by kelceycoe
    Thanks for such a wonderful script. How do I cite you as a credit for when I use it?

    I got this error:
    HTTP/1.1 406 Not Acceptable
    Date: Thu, 08 Feb 2007 19:12:41 GMT
    Server: Apache/1.3.37 (Unix) mod_auth_passthrough/1.8 mod_log_bytes/1.2 mod_bwlimited/1.4 FrontPage/5.0.2.2635.SR1.2 mod_ssl/2.8.28 OpenSSL/0.9.7a PHP-CGI/0.1b
    Connection: close
    Content-Type: text/html; charset=iso-8859-1

    <!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">
    <HTML><HEAD>
    <TITLE>406 Not Acceptable</TITLE>
    </HEAD><BODY>
    <H1>Not Acceptable</H1>
    An appropriate representation of the requested resource /politicstestresults/post_dump.php could not be found on this server.<P>
    <HR>
    <ADDRESS>Apache/1.3.37 Server at www.kelceycoe.com Port 80</ADDRESS>
    </BODY></HTML>

    I've uploaded the files to my upload directory as shown, and chomodded the directory and php files as 777. Is that right or am I doing something way wrong? Thanks.

Page 1 of 2 12 LastLast

Posting Permissions

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



Featured


Click Here to Expand Forum to Full Width

Survey posted by VBForums.