Hi DonManfred i have added your code in my project and show me this error
how can i fix?
Error description: MultipartPost is declared twice. You should either remove the library reference or the code module.
i dont make any change in your code only put this on my project
hc.Initialize("hc")
Dim Response As HttpResponse
Dim fromserver As String
'Add files
Dim files As List
files.Initialize
Dim fd As FileData
fd.Initialize
fd.Dir = File.DirRootExternal
fd.FileName = file_to_upload
fd.KeyName = "files"
fd.ContentType = "application/octet-stream"
files.Add(fd)
'Add second file
'Dim fd As FileData
'fd.Initialize
'fd.Dir = File.DirAssets
'fd.FileName = "1.png"
'fd.KeyName = "upfile"
'fd.ContentType = "application/octet-stream"
'files.Add(fd)
'Add name / values pairs (parameters)
'Dim NV As Map
'NV.Initialize
'NV.Put("note1", "abc")
'NV.Put("note2", "def")
Dim req As HttpRequest
req = MultipartPost.CreatePostRequest("http://www.xxxxx.com/upload.php", files)
hc.Execute(req, 1)
if (!empty($_FILES["files"])) {
$uploaded_file_name = $_FILES["files"]["name"];
$uploaded_file = $_FILES["files"]["tmp_name"];
// test if you got the file
echo "the file uploaded was " . $upload_file_name;
}
I am not sure I understand your question. However, the web site is hosted by GoDaddy. It is Windows (not Linux) and supports IIS7. It uses php 5.2.17. I can use this php script by browsing a file on my PC and upload it using a submit form, but have not figured out how to use B4A to intereact with it:Which file upload methods does your server support?
<?php
$target_dir = "uploads/";
$target_file = $target_dir . basename($_FILES["fileToUpload"]["name"]);
$uploadOk = 1;
$FileType = pathinfo($target_file,PATHINFO_EXTENSION);
// Check if image file is a actual image or fake image
if(isset($_POST["submit"])) {
$check = getimagesize($_FILES["fileToUpload"]["tmp_name"]);
if($check !== false) {
echo "File is not a text file - <br>" . $check["mime"] . ".";
$uploadOk = 0;
} else {
echo "File is a text file.<br>";
$uploadOk = 1;
}
}
/*
// Check if file already exists
if (file_exists($target_file)) {
echo "Sorry, file already exists.<br>";
$uploadOk = 0;
}
*/
// Check file size
if ($_FILES["fileToUpload"]["size"] > 5000000) {
echo "Sorry, your file is too large.";
$uploadOk = 0;
}
// Allow certain file formats
if($FileType != "txt" && $FileType != "tab" && $FileType != "csv"
&& $FileType != "asc" ) {
echo "Sorry, only txt, tab, csv and asc files are allowed.";
$uploadOk = 0;
}
// Check if $uploadOk is set to 0 by an error
if ($uploadOk == 0) {
echo "Sorry, your file was not uploaded.";
// if everything is ok, try to upload file
} else {
if (move_uploaded_file($_FILES["fileToUpload"]["tmp_name"], $target_file)) {
echo "The file ". basename( $_FILES["fileToUpload"]["name"]). " has been uploaded.";
} else {
echo "Sorry, there was an error uploading your file.";
}
}
?>
you are checking for the file fileToUpload but you set$check = getimagesize($_FILES["fileToUpload"]["tmp_name"]);
fd.KeyName = "files"
fd.KeyName = "fileToUpload"
I have not tried to use that script with B4A yet because I am not sure how to do it. It is not the problem. But my problem is: I tried your project in Post #6, but could not get it to work. I did not understand what name values, note1, note2, etc meant. Don't you also use a user and a password to access the web site?you are checking for the file fileToUpload but you set
I did not understand what name values, note1, note2, etc meant.
Dim NV As Map
NV.Initialize
NV.Put("uname", "mysuperduperusername")
NV.Put("upass", "secret")
Have a look at this example it uses erels multipartpost.bas. It uploads two files to a phpscript. On phpside the uploads are written to uploads-folder
Edit 29. August 2015:
I´ve added a new version of the example. This example uses the new okHTTP-Library.
Please note that i need to change the module multipartpost.bas to be compatible with the new okHTTP
Start with creating a NEW thread in the questionsforum. Post the relevant code.can any1 help me?
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?