Results 1 to 27 of 27

Thread: VB6 File Upload

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    Jul 2007
    Posts
    530

    VB6 File Upload

    Hello i'am trying to upload a file from example C:\ and then upload it to server via vb6 & php & chmod uploads folder to 0777

    here what i have i have setup in local it work but on remote not work



    Thanks
    Last edited by killer7k; Nov 3rd, 2009 at 05:37 AM.

  2. #2
    Addicted Member Xiphias3's Avatar
    Join Date
    Jan 2009
    Location
    Clarendon, Jamaica
    Posts
    188

    Re: VB6 File Upload

    Hmmmm.... PHP code
    OK, I've never uploaded a file to a server, but I've downloaded a few. I don't believe InternetOpenURL will work here, as that function seems to be used in downloading direct link files. In any case, i don't know anything so here's a few APIs I think you should get familiar with.

    vb Code:
    1. ' Allow access to the Inet functions
    2. InternetOpen
    3.  
    4. ' To connect to a remote computer. Allows for Authentication via username and password parameters
    5. InternetConnect
    6.  
    7. ' Create and Open a HTTP Request. lpszVerb will most likely be PUT to upload a file. GET is used to download the file
    8. HttpOpenRequest
    9.  
    10. ' Send the request. Non-zero means success.
    11. HttpSendRequestEx
    12.  
    13. ' Never used these :p
    14. InternetWriteFile
    15.  
    16. HttpEndRequest
    17.  
    18. ' For cleanup of open Internet handles
    19. InternetCloseHandle

    Look those up on MSDN. I would try to make an example, but dont really know where i'd up the file.

  3. #3

    Thread Starter
    Fanatic Member
    Join Date
    Jul 2007
    Posts
    530

    Re: VB6 File Upload

    Thanks but the code that i did posted work for me here on my local machine perfect but dont work on remote server

    hope someone can help me

  4. #4

    Thread Starter
    Fanatic Member
    Join Date
    Jul 2007
    Posts
    530

    Re: VB6 File Upload

    anyone can help?

  5. #5
    PowerPoster
    Join Date
    Dec 2004
    Posts
    25,618

    Re: VB6 File Upload

    i believe it is to do with permissions on the server, but i was unable to resolve the problem
    i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
    Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next

    dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part

    come back and mark your original post as resolved if your problem is fixed
    pete

  6. #6

    Thread Starter
    Fanatic Member
    Join Date
    Jul 2007
    Posts
    530

    Re: VB6 File Upload

    Quote Originally Posted by westconn1 View Post
    i believe it is to do with permissions on the server, but i was unable to resolve the problem
    Hi westconn1 ,

    i did chmod the uploads folder on remote server & it's working for me here on my local machine

    can you tell me which permissions are you talking about ?

    Thanks

  7. #7
    PowerPoster
    Join Date
    Dec 2004
    Posts
    25,618

    Re: VB6 File Upload

    here is the php i was using to return results to browser
    php Code:
    1. <?php
    2. foreach($_POST as $key => $value){
    3.  
    4.  
    5.   if($value != ""){
    6.     $message .= $key. " --------- " . $value. "\n" ;
    7.  
    8.     echo   $key . " ----- " . $value. "<br>";
    9.    }else{
    10.     $error = true;
    11.    
    12.   }
    13. }
    14. foreach($_FILES as $myfile => $xxx){
    15. foreach($xxx as $uploadedfile => $name){
    16. echo $uploadedfile . " ----- " . $name . "<br>";
    17. }
    18.  }
    19. $target_path = getcwd(). "/upload/";
    20.  
    21. echo $_FILES["uploadedfile"]["tmp_name"]."<br>";
    22. echo exec('whoami');
    23. chmod($_FILES["uploadedfile"]["name"],0777);
    24. echo substr(sprintf('%o', fileperms($_FILES["uploadedfile"]["tmp_name"])), -4)."<br>";
    25.  
    26.  
    27. // ulink($_FILES["uploadedfile"]["tmp_name"]);
    28.  
    29. echo $_FILES["uploadedfile"]["name"]."<br>";
    30.  
    31. $target_path = $target_path . basename( $_FILES['uploadedfile']['name']);
    32.   //    copy($_FILES["uploadedfile"]["tmp_name"], $target_path . $_FILES["uploadedfile"]["name"]);
    33. echo $target_path."<br>";
    34. if(move_uploaded_file($_FILES['uploadedfile']['tmp_name'], $target_path)) {
    35.     echo "The file ".  basename( $_FILES['uploadedfile']['name']).
    36.    " has been uploaded";
    37. } else{
    38.     echo "There was an error uploading the file, please try again!";
    39. }
    40.  
    41.  
    42. ?>
    i have not played with it for a while, i was just using a file input for testing
    i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
    Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next

    dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part

    come back and mark your original post as resolved if your problem is fixed
    pete

  8. #8
    Lively Member
    Join Date
    Jan 2008
    Posts
    114

    Re: VB6 File Upload

    Some php will go under as php scripts. and if your having a site hosted you wonna make sure your provider allows php scripts to be used. I believe that was 1 of my problems otherwise the code in 1 topics which is where u got that code from works perfectly.
    "What is a hackers worst nightmare you may ask? Vista! Not that its hard to bypass its just that it gives you stupid annoying errors!"


  9. #9
    PowerPoster
    Join Date
    Dec 2004
    Posts
    25,618

    Re: VB6 File Upload

    the php code ran and echoed everything back to the browser, but no file was uploaded, whether is used moveuploadedfile or copy
    other php scripts work correctly
    the file permissions returned to the browser were not changed by the chmod
    i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
    Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next

    dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part

    come back and mark your original post as resolved if your problem is fixed
    pete

  10. #10

    Thread Starter
    Fanatic Member
    Join Date
    Jul 2007
    Posts
    530

    Re: VB6 File Upload

    Thanks Guy for your answer . Unfortunately, after reading & googling i think the get method on that will not work at least on that way..

    and yes the host is Linux one so PHP is working fine

    so i moved to another way using POST data which will require 1 html file and 1 php file & http post header on vb6 (which i have problem right now )



    now i'am trying to use http header using InternetOpenurl API to i can upload that file using post data

    hope someone can help me

    Thanks
    Last edited by killer7k; Nov 3rd, 2009 at 05:38 AM.

  11. #11
    PowerPoster
    Join Date
    Dec 2004
    Posts
    25,618

    Re: VB6 File Upload

    that was more or less what i started with, then added to for debugging purposes,
    which showed every thing as correct, but the file was not saved
    i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
    Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next

    dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part

    come back and mark your original post as resolved if your problem is fixed
    pete

  12. #12

    Thread Starter
    Fanatic Member
    Join Date
    Jul 2007
    Posts
    530

    Re: VB6 File Upload

    Quote Originally Posted by westconn1 View Post
    that was more or less what i started with, then added to for debugging purposes,
    which showed every thing as correct, but the file was not saved
    you mean you didnt get it working ?

    i really dunno what's wrong with that code and Pezster said it's working how !!!??

    Thanks

  13. #13
    Lively Member
    Join Date
    Jan 2008
    Posts
    114

    Re: VB6 File Upload

    This code might / might not work. Last time i tryed it, it didn't work but I believe that was due to my webhost not allowing phpscripts to be used considering my friend had another site and this exact code did work.


    PHP Code:
    <?php

    //Put this php upload script in your apache php webserver.
    //Set the url to this script in your vb upload client

    $location "";      //Left blank if upload in same folder
    $max_size 1000000//File upload size

    print("$value1 $value2\r\n"); //Check for extra posted variable - u can add ur own here

    //This loop here will save ur file to the server
    for ($num 1$num $slots+1$num++){

        
    $event "Success";
        
        
    // Check if upload for field is required
        
    if (! $_FILES['upload'.$num]['name'] == ""){
          if (
    $_FILES['upload'.$num]['size'] < $max_size) {        
            
    move_uploaded_file($_FILES['upload'.$num]['tmp_name'],$location.$_FILES['upload'.$num]['name']) or $event "Failure";
           } else {
            
    $event "File too large!";
           }
           print(
    "Uploading File $num $event\r\n");
        }
      }

    ?>

    Code:
    Private Sub Command1_Click()
    
    Dim iArray
    
    'Set your filename to upload here
    iArray = Array("image1.jpg", "image2.jpg", "image3.jpg")
    
    'Set path to php upload script here
    Text1.Text = UploadFiles(iArray, "http://site/getfile.php", App.Path, Text2.Text)
    
    End Sub
    "What is a hackers worst nightmare you may ask? Vista! Not that its hard to bypass its just that it gives you stupid annoying errors!"


  14. #14
    Lively Member
    Join Date
    Jan 2008
    Posts
    114

    Re: VB6 File Upload

    If that code doesnt code work that I posted above theres another way around it if you have a website easier idk just all depends if you dont wonna login ftp like i did or not. Theres php scripts that allow user input on an HTML page, search for file, press upload button. You can have the vb program fill in all thoose fields and done, just adds an extra HTML page to your site.
    "What is a hackers worst nightmare you may ask? Vista! Not that its hard to bypass its just that it gives you stupid annoying errors!"


  15. #15
    Lively Member putta's Avatar
    Join Date
    Oct 2004
    Location
    Original Citizen Of This Planet
    Posts
    86

    Re: VB6 File Upload

    The path $target_path = "uploads/"; is pointing to an absolute path in the remote webserver is it? check that out.. if the remote webserver you are trying to upload to is a shared webhosting server then the path for the PHP script has to be declared properly. I have tried this before for file uploads.

    I had to use the path as below to get the file upload going...

    /home/<loginname>/public_html/

    in your case it would be possible to verify the actual path for upload using the filemanager console the web service provider would have provided to you. I would suggest you use complete path instead of relative path for uploads as there will be no confusion. If you have doubt over permissions try setting the path to tmp folder of the remote server which would probably be /home/<loginname>/tmp



    -Putta

  16. #16
    PowerPoster
    Join Date
    Dec 2004
    Posts
    25,618

    Re: VB6 File Upload

    i returned the target path to the browser, certainly looked correct, for my server
    the current user for the php script returns apache chmod did not appear to change the permissions for the file, maybe apache does not have enough permissions to change the file permissions
    i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
    Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next

    dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part

    come back and mark your original post as resolved if your problem is fixed
    pete

  17. #17

    Thread Starter
    Fanatic Member
    Join Date
    Jul 2007
    Posts
    530

    Re: VB6 File Upload

    Thanks Guy for your answer . Unfortunately, i did tried the first code i did put on 3 different host & all are chmoded but none work (work for me on my local machine)

    however i hope someone can help me with post data with the code i did post for html & php file

    @Pezster

    where is UploadFiles Function ??

    my idea was to use http post header data but dont know how to on vb6

    Thanks & still waiting someone can help

  18. #18
    Lively Member
    Join Date
    Jan 2008
    Posts
    114

    Re: VB6 File Upload

    what do you mean by UploadFiles function? Php you really just open the site and write w.e the required informtation to the end of the url ex. Text1.Text = UploadFiles(iArray, "http://site/getfile.php", App.Path, Text2.Text)
    "What is a hackers worst nightmare you may ask? Vista! Not that its hard to bypass its just that it gives you stupid annoying errors!"


  19. #19

    Thread Starter
    Fanatic Member
    Join Date
    Jul 2007
    Posts
    530

    Re: VB6 File Upload

    Quote Originally Posted by Pezster View Post
    what do you mean by UploadFiles function? Php you really just open the site and write w.e the required informtation to the end of the url ex. Text1.Text = UploadFiles(iArray, "http://site/getfile.php", App.Path, Text2.Text)
    what is UploadFiles ?

    from which class does it come ?

    please can you help with POST Data ? look at post 10
    cause the get will not work

    Thanks

  20. #20
    Lively Member
    Join Date
    Jan 2008
    Posts
    114

    Re: VB6 File Upload

    this?

    Code:
    'You need reference to Microsoft WinHTTP Services 5.0 or 5.1 to use this example
    
    'Credit to Joseph Z. Xu ([email protected])
    'Modified by Mohd Idzuan Alias ([email protected]) August 18, 2004
    
    Dim WinHttpReq As WinHttp.WinHttpRequest
    Const HTTPREQUEST_SETCREDENTIALS_FOR_SERVER = 0
    Const HTTPREQUEST_SETCREDENTIALS_FOR_PROXY = 1
    Const BOUNDARY = "Xu02=$"
    Const HEADER = "--Xu02=$"
    Const FOOTER = "--Xu02=$--"
    
    Function UploadFiles(strFileName As Variant, strURL As String, DirPath As String, Optional postVar As String, _
                         Optional strUserName As String, Optional strPassword As String) As String
    
        Dim fname As String
        Dim strFile As String
        Dim strBody As String
        Dim aPostBody() As Byte
        Dim nFile As Integer
            
        Set WinHttpReq = New WinHttpRequest
    
        ' Turn error trapping on
        On Error GoTo SaveErrHandler
    
        ' Assemble an HTTP request.
        strURL = strURL & "?slots=" & CStr(UBound(strFileName) + 1) & "&" & postVar
        WinHttpReq.Open "POST", strURL, False
        Debug.Print strURL
        
        If strUserName <> "" And strPassword <> "" Then
            ' Set the user name and password.
            WinHttpReq.SetCredentials strUserName, strPassword, _
            HTTPREQUEST_SETCREDENTIALS_FOR_SERVER
        End If
        
        '-------------------------- Becareful not to mingle too much here -----------------------------------
        
        ' Set the header
        WinHttpReq.SetRequestHeader "Content-Type", "multipart/form-data; boundary=" & BOUNDARY
          
        ' Assemble the body
        strBody = HEADER                        ' Starting tag
        
        For i = 0 To UBound(strFileName)
        
            ' Grap the name
            fname = strFileName(i)
            
            ' Grap the file
            strFile = getFile(DirPath & "\" & fname)
            
                strBody = strBody & vbCrLf & "Content-Disposition: form-data; name=""" & "upload" & _
                (i + 1) & """; filename=""" & fname & """ " & vbCrLf & "Content-type: file" & _
                vbCrLf & vbCrLf & strFile & vbCrLf
            
            If i < UBound(strFileName) Then
                strBody = strBody & "--Xu02=$" ' This is boundary tag between two files
            End If
            strFile = ""
            
        Next i
        
        strBody = strBody & FOOTER             ' Ending tag
        '----------------------------------------------------------------------------------------------------
        
        ' Because of binary zeros, post body has to convert to byte array
        aPostBody = StrConv(strBody, vbFromUnicode)
        
        ' Send the HTTP Request.
        WinHttpReq.Send aPostBody
        
        ' Display the status code and response headers.
        'UploadFiles = WinHttpReq.GetAllResponseHeaders & "  " & WinHttpReq.ResponseText
        UploadFiles = WinHttpReq.ResponseText
        
        Set WinHttpReq = Nothing
        
        Exit Function
        
    SaveErrHandler:
        UploadFiles = Err.Description
        
        Set WinHttpReq = Nothing
        
    End Function
    Function getFile(strFileName As String) As String
    
        Dim strFile As String
        
        ' Grap the file
        nFile = FreeFile
        Open strFileName For Binary As #nFile
        strFile = String(LOF(nFile), " ")
        Get #nFile, , strFile
        Close #nFile
        
        getFile = strFile
        
    End Function
    "What is a hackers worst nightmare you may ask? Vista! Not that its hard to bypass its just that it gives you stupid annoying errors!"


  21. #21

    Thread Starter
    Fanatic Member
    Join Date
    Jul 2007
    Posts
    530

    Re: VB6 File Upload

    dont work Pezster

    tried & tried no error but not work

    could someone help just to send a text file from C:\ to ftp server using php ?
    could anybody look at my post 10 ?

    Thanks

  22. #22

    Thread Starter
    Fanatic Member
    Join Date
    Jul 2007
    Posts
    530

    Re: VB6 File Upload

    here what exactly trying to do on vb6 + php

    http://www.codeproject.com/KB/cs/uploadfileex.aspx

  23. #23
    Lively Member
    Join Date
    Jan 2008
    Posts
    114

    Re: VB6 File Upload

    I have no idea lol like I said the code works and then doesnt work i believe on webhost. I dont have my site hosted atm so i cant really be of to much of help. If you do get it working please be sure to post the working code etc here.

    http://www.tizag.com/phpT/fileupload.php
    Last edited by Pezster; Sep 12th, 2009 at 10:42 PM.
    "What is a hackers worst nightmare you may ask? Vista! Not that its hard to bypass its just that it gives you stupid annoying errors!"


  24. #24

    Thread Starter
    Fanatic Member
    Join Date
    Jul 2007
    Posts
    530

    Re: VB6 File Upload

    ok i did succed on getting it working but on vb.net hope someone can convert that to vb
    yes tested it work both on local & remote server
    Last edited by killer7k; Nov 3rd, 2009 at 05:38 AM.

  25. #25

    Thread Starter
    Fanatic Member
    Join Date
    Jul 2007
    Posts
    530

    Re: VB6 File Upload

    someone can help me ?

  26. #26

    Thread Starter
    Fanatic Member
    Join Date
    Jul 2007
    Posts
    530

    Re: VB6 File Upload

    someone can help me plz ?

  27. #27

    Thread Starter
    Fanatic Member
    Join Date
    Jul 2007
    Posts
    530

    Re: VB6 File Upload

    bump

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