When the user clicks the upload picture button , I want them to select a picture which will then be saved to the images folder in my corona app project and then be saved to the database so it can be shown on the users profile page on my corona app . I have only done a small part to this which is giving the user the option to view their photos . Can someone help me with the rest or if you have an easier way I would follow . Here is what I have so far :
profile.lua :
-- Selection completion listener local function onComplete( event ) local photo = event.target if photo then print( "photo w,h = " .. photo.width .. "," .. photo.height ) end end local button = widget.newButton( { shape = "roundedRect", left = 70, top = 350, id = "pfp", label = "Upload picture", onEvent = pickPhoto, fillColor = { default={ 1, 0.2, 0.5, 0.7 }, over={ 1, 0.2, 0.5, 1 } }, labelColor = { default={ 2, 4, 1.5 }, over={ 2, 5, 1.5, 2.2 } } } ) local function pickPhoto( event ) media.selectPhoto( { mediaSource = media.SavedPhotosAlbum, listener = onComplete, origin = button.contentBounds, permittedArrowDirections = { "right" }, destination = { baseDir=system.TemporaryDirectory, filename="image.jpg" } }) end local MultipartFormData = require("class\_MultipartFormData") local multipart = MultipartFormData.new() local path=system.pathForFile( "image.jpg", system.TemporaryDirectory ) multipart:addFile("Image", path, "image/jpg", "image.jpg") local params = {} params.body = multipart:getBody() params.headers = multipart:getHeaders() -- Headers not valid until getBody() is called. network.request("https://your.server.url/services/imageupload?parameter=1", "POST", listener, params)
class_MultipartFormData.lua :
https://github.com/benglard/Augment/blob/master/App/class_MultipartFormData.lua
I have all the code there in mine .
upload.php :
\<?php ini\_set('display\_errors', 1); ini\_set('display\_startup\_errors', 1); error\_reporting(E\_ALL); $servername = "localhost"; $username = "username"; $password = "password"; $database = "db"; $con = new mysqli($servername, $username, $password, $database); if($con == true) { } // Check connection if ($con-\>connect\_error) { die("Connection failed: " . $con-\>connect\_error); } include("auth\_login.php"); $target\_dir = "images/uploads/"; $target\_file = $target\_dir . basename($\_FILES["fileToUpload"]["name"]); $uploadOk = 1; $imageFileType = pathinfo($target\_file,PATHINFO\_EXTENSION); // Check if image file is a actual image or fake image if(isset($\_POST["change"])) { move\_uploaded\_file($\_FILES["fileToUpload"]["tmp\_name"], $target\_file); if($check !== false) { echo "picture uploaded"; $uploadOk = 1; } else { echo "File is not an image."; $uploadOk = 0; } } ?\>
please help me thanks