Send local file to my web server


#1

Hi,
I want to send a local file to my web server.

Function Button2_onclick()
var input = document.createElement("input")
input.type = "file"
input.click()
End Function

This popups a Dialog, where I can choose a file or a picture on a mobile.
But how do I get the choose file to my web server?
I try it with this command:

Ajax("upload.php","POST",input.value)  ' I think input.value is not correct

But there is no upload to my php script.

<?php
if (isset($_FILES['datei']))
{
    move_uploaded_file($_FILES['datei']['tmp_name'], 'upload/'.$_FILES['datei']['name']);
}
?>

How do I get the file to my web server

Thank you for help

Udo


#2

I edited your post, adding ``` before and after the code. It formats nicely now.

Did you look at the AjaxPost sample? It uploads files too. See if it works for you.


#3

Thank you for formatting!

But the Ajax Example only writes a textbox.value (string) to a file on a server. I want to upload a file.


#4

You need to send the file as a string.


#5

now I have a solution:

with button3 opens the window to choose a file in a browser or image on the mobile
with button2 the file was transfer to the server, but remember, you need write-rights in the directory on the server
Now I can build my own file box.

best regards
Udo

 Function Button2_onclick()
 formData = new FormData()
 client = new XMLHttpRequest()
 formData.append("datei",input.files[0])
 client.open("POST", "upload.php")
 client.send(formData)
End Function

Function Button3_onclick()
 input = document.createElement("input")
 input.type = "file"
 input.click()
End Function