Hey everyone!
I’m trying to upload an image with an string to my web site through php
the code works fine in simulator, I can upload my image BUT I can’t open image after uploaded and in device I can’t upload I get an error:
“Lua Runtime Error: lua+pcall failed with status: 2, error message is: assertion failed!”
someone can please help me?
The code for this:
local MultipartFormData = require("class\_MultipartFormData")
local multipart = MultipartFormData.new()
multipart:addHeader("Customer-Header", "Custom Header Value")
multipart:addField("myFieldName","myFieldValue")
multipart:addField("banana","yellow")
multipart:addFile("myfile", system.pathForFile( "myfile.jpg", system.DocumentsDirectory ), "image/jpeg", "myfile.jpg")
local params = {}
params.body = multipart:getBody() -- Must call getBody() first!
params.headers = multipart:getHeaders() -- Headers not valid until getBody() is called.
local function networkListener( event )
if ( event.isError ) then
print( "Network error!")
else
print ( "RESPONSE: " .. event.response )
end
end
network.request( "http://www.example.com", "POST", networkListener, params)
$myparam = $\_POST['myFieldName'];
echo $myparam;
$target\_path = "uploads/";
$target\_path = $target\_path . basename( $\_FILES['myfile']['name']);
if(move\_uploaded\_file($\_FILES['myfile']['tmp\_name'], $target\_path)) {
echo "The file ". basename( $\_FILES['myfile']['name']).
" has been uploaded";
} else{
echo "There was an error uploading the file, please try again!";
}
[import]uid: 23063 topic_id: 18361 reply_id: 318361[/import]
[import]uid: 52491 topic_id: 18361 reply_id: 70513[/import]