|
-
Sep 10th, 2009, 05:49 PM
#1
Thread Starter
Fanatic Member
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.
-
Sep 10th, 2009, 07:12 PM
#2
Addicted Member
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:
' Allow access to the Inet functions
InternetOpen
' To connect to a remote computer. Allows for Authentication via username and password parameters
InternetConnect
' Create and Open a HTTP Request. lpszVerb will most likely be PUT to upload a file. GET is used to download the file
HttpOpenRequest
' Send the request. Non-zero means success.
HttpSendRequestEx
' Never used these :p
InternetWriteFile
HttpEndRequest
' For cleanup of open Internet handles
InternetCloseHandle
Look those up on MSDN. I would try to make an example, but dont really know where i'd up the file.
-
Sep 10th, 2009, 07:14 PM
#3
Thread Starter
Fanatic Member
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
-
Sep 10th, 2009, 11:14 PM
#4
Thread Starter
Fanatic Member
-
Sep 11th, 2009, 02:44 AM
#5
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
-
Sep 11th, 2009, 11:13 AM
#6
Thread Starter
Fanatic Member
Re: VB6 File Upload
 Originally Posted by westconn1
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
-
Sep 11th, 2009, 04:23 PM
#7
Re: VB6 File Upload
here is the php i was using to return results to browser
php Code:
<?php foreach($_POST as $key => $value){ if($value != ""){ $message .= $key. " --------- " . $value. "\n" ; echo $key . " ----- " . $value. "<br>"; }else{ $error = true; } } foreach($_FILES as $myfile => $xxx){ foreach($xxx as $uploadedfile => $name){ echo $uploadedfile . " ----- " . $name . "<br>"; } } $target_path = getcwd(). "/upload/"; echo $_FILES["uploadedfile"]["tmp_name"]."<br>"; echo exec('whoami'); chmod($_FILES["uploadedfile"]["name"],0777); echo substr(sprintf('%o', fileperms($_FILES["uploadedfile"]["tmp_name"])), -4)."<br>"; // ulink($_FILES["uploadedfile"]["tmp_name"]); echo $_FILES["uploadedfile"]["name"]."<br>"; $target_path = $target_path . basename( $_FILES['uploadedfile']['name']); // copy($_FILES["uploadedfile"]["tmp_name"], $target_path . $_FILES["uploadedfile"]["name"]); echo $target_path."<br>"; if(move_uploaded_file($_FILES['uploadedfile']['tmp_name'], $target_path)) { echo "The file ". basename( $_FILES['uploadedfile']['name']). " has been uploaded"; } else{ echo "There was an error uploading the file, please try again!"; } ?>
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
-
Sep 11th, 2009, 04:34 PM
#8
Lively Member
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!"

-
Sep 11th, 2009, 04:53 PM
#9
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
-
Sep 11th, 2009, 10:50 PM
#10
Thread Starter
Fanatic Member
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.
-
Sep 12th, 2009, 12:11 AM
#11
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
-
Sep 12th, 2009, 08:41 AM
#12
Thread Starter
Fanatic Member
Re: VB6 File Upload
 Originally Posted by westconn1
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
-
Sep 12th, 2009, 12:52 PM
#13
Lively Member
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!"

-
Sep 12th, 2009, 01:16 PM
#14
Lively Member
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!"

-
Sep 12th, 2009, 01:32 PM
#15
Lively Member
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
-
Sep 12th, 2009, 05:33 PM
#16
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
-
Sep 12th, 2009, 09:03 PM
#17
Thread Starter
Fanatic Member
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
-
Sep 12th, 2009, 09:09 PM
#18
Lively Member
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!"

-
Sep 12th, 2009, 09:17 PM
#19
Thread Starter
Fanatic Member
Re: VB6 File Upload
 Originally Posted by Pezster
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
-
Sep 12th, 2009, 09:31 PM
#20
Lively Member
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!"

-
Sep 12th, 2009, 09:59 PM
#21
Thread Starter
Fanatic Member
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
-
Sep 12th, 2009, 10:24 PM
#22
Thread Starter
Fanatic Member
-
Sep 12th, 2009, 10:37 PM
#23
Lively Member
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!"

-
Sep 12th, 2009, 11:51 PM
#24
Thread Starter
Fanatic Member
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.
-
Sep 13th, 2009, 05:27 PM
#25
Thread Starter
Fanatic Member
Re: VB6 File Upload
someone can help me ?
-
Sep 14th, 2009, 04:53 PM
#26
Thread Starter
Fanatic Member
Re: VB6 File Upload
someone can help me plz ?
-
Oct 15th, 2009, 05:34 PM
#27
Thread Starter
Fanatic Member
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|