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 :)
Printable View
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 :)
Hmmmm.... PHP code :confused: :confused: :confused: :confused:
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.
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 :)
anyone can help?
i believe it is to do with permissions on the server, but i was unable to resolve the problem
here is the php i was using to return results to browser
i have not played with it for a while, i was just using a file input for testingphp 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!"; } ?>
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.
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
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
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
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
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.
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
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
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 :rolleyes:
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)
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
dont work Pezster
tried & tried no error but not work :rolleyes:
could someone help just to send a text file from C:\ to ftp server using php ?
could anybody look at my post 10 ?
Thanks
here what exactly trying to do on vb6 + php
http://www.codeproject.com/KB/cs/uploadfileex.aspx
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
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 :)
someone can help me ? :rolleyes:
someone can help me plz ? :rolleyes:
bump