how to upload multiple images from android to php server example - upload

I need to upload the multiple images in a folder from android to php server in a for each or for loop. image path should store in database and image source should store in folder.
following what i have tried
$jsonarr = $_POST['ImageArr'];
$decodedjson = json_decode($jsonarr,TRUE);
for( $i=0; $i < count($decodedjson); $i++ ) {
$destdir ="uploads/".$image_unique_no;
$img = file_get_contents($decodedjson[$i]);
file_put_contents( $destdir.substr( $decodedjson[$i], strrpos($decodedjson[$i],'/')), $img);
}

<?php
$filesArray = $_FILES['ImageArr'];
$file_count = count($filesArray['name']);
for ($i=0; $i< $file_count; $i++)
{
move_uploaded_file($filesArray['tmp_name'][$i], "upload/".time()."_".$filesArray['name'][$i]);
}
?>
get images array posted from android device.

Related

Ionic media plugin does not play locally stored mp3 files on iOS

I'm trying to make a mp3 player with ionic media plugin.
First I download song on local storage via path
let filePath;
if(this.platform.is('android'))
{
filePath = this.file.externalDataDirectory;
}
else
{
filePath = this.file.documentsDirectory;
}
filePath = filePath +'810.mp3';
after that we get such path
file:///var/mobile/Containers/Data/Application/5DC6D2D0-6336-4C6E-A39E-5D5FD7D8AF7B/Library/Cloud/810.mp3
So for example we have such an object
track = {
'name':'Name of Song',
'filePath': filePath
}
I create
const file:MediaObject = this.media.create(track.filePath);
and when time comes to play
file.play();
Whole app crashes without giving me a hint of error.
This plugin normally plays files on Android from both localPath and internetPath.
On iOS it plays only from internet but crashes when plays local files. Please help.
So I found the solution. It was here.
https://forum.ionicframework.com/t/ios-9-cant-play-audio-video-files-that-are-downloaded-to-device/37580
For example.
track = {
'name':'Name of Song',
'filePath': '';
}
if(this.platform.is('android'))
{
track.filePath = this.file.externalDataDirectory;
}
else
{
track.filePath = this.file.documentsDirectory;
}
track.filePath = track.filePath +'810.mp3';
const transfer = this.transfer.create();
let url = "http://someLink.com/someFileName.mp3";
transfer.download(url, track.filePath).then((entry)=>{
// **code here will be executed when track is downloaded**
// and only for ios local file system we need to create a special link to this file
// so that cordova media plugin could read this file and if necessary to delete it
// with cordova file plugin by this link also.
if(this.platform.is('ios'))
this.file.resolveLocalFilesystemUrl(track.filePath).then((entry)=>{
track.filePath = entry.toInternalURL;
});
Actually there was another way to make iOS play file by removinh file:// from beging of track.filePath but then you will face with another issue. You won't be able do delete it by this path later.

Getting error when uploading video using Tweetinvi

I am trying to upload files larger than 5MB but less than 15MB. In this case its 10MB... sample video from sample-videos.com
I am using Tweetinvi, and it works great with files less than 5MB, but fails on chunked uploads. I've tried the easy and the hard way.
Easy way:
var video = File.ReadAllBytes(#"D:\Projects\SampleVideo_1280x720_10mb.mp4");
var media = Upload.UploadVideo(video); // Error here... Invalid Content
var tweet = user.PublishTweet(message, new PublishTweetOptionalParameters
{
Medias = { media }
});
I've pulled in the Tweetinvi solution from Git (currently 0.9.13.0 repository here) and see that the above is getting an error "Invalid Content" when calling Upload.UploadVideo(...). It appears to fail on the command FINALIZE.
Tried the hard way:
using (var fileStream = File.OpenRead(#"D:\Projects\SampleVideo_1280x720_10mb.mp4"))
{
var initSucceeded = uploader.Init("video/mp4", (int)fileStream.Length);
byte[] buffer = new byte[4900000]; //Your chunk MUST be 5MB or less or else the Append function will fail silently.
int bytesRead = 0;
while ((bytesRead = fileStream.Read(buffer, 0, buffer.Length)) > 0)
{
byte[] copy = new byte[bytesRead];
Buffer.BlockCopy(buffer, 0, copy, 0, bytesRead);
var appendResult = uploader.Append(new ChunkUploadAppendParameters(copy, "video/mp4", null) { SegmentIndex = uploader.NextSegmentIndex });
}
var video = uploader.Complete(); // Fails here... Returned error: Segments do not add up to provided total file size
var tweet = user.PublishTweet(message, new PublishTweetOptionalParameters()
{
//Medias = { video }
MediaIds = { video.MediaId.Value }
});
}
The above fails on upload.Complete() with the Twitter API returning "Segments do not add up to provided total file size"
What am I missing?
TIA
I think the problem you have is with the video file. The video seems to be using a 6 channels audio and Twitter Public Upload API only allow developers to upload video with mono or stereo audio.
Source : https://dev.twitter.com/rest/media/uploading-media
I am no expert in video properties so feel free to prove me wrong if I am.
The above fails on upload.Complete() with the Twitter API returning "Segments do not add up to provided total file size"
This error means that you are not actually sending all the byte that you promised Twitter. During the INIT, you tell Twitter the size of your media, if what it receives in the combined APPEND is not equals to the value you specified in the INIT, the error you described is thrown.
PS : I have tried using a 2 channels 14.8 MB mp4 and it works properly. var media = Upload.UploadVideo(binary);

How to upload file using LrHttp.posMultipart in Lua

I need to send the image file using multipart request from Lightroom to my local web service using Lua language.
I have tested using sending headers also but not working...
I have created a function :
function testupload(filepath) --created inside LrTasks
local url = "http://localhosturl"
local mycontent = {
{
name = "lightroom_message",
value = "sent from lightroom plugin multiparta"
},
{
name = 'file',
filePath = filepath,
fileName = LrPathUtils.leafName(filepath),
contentType = 'image/jpeg'
--contentType = 'multipart/form-data'
}
}
local response, headers = LrHttp.postMultipart(url, mycontent)
end
But my web service is not getting called properly and I am using LrHttp.postMultipart() method to do so..
If I am sending just this param to web service (then working fine):
{
name = "lightroom_message",
value = "sent from lightroom plugin multiparta"
}
but when I include my file payload then its not working using pure Lua implementation.
Everything was correct but just a technical mistake...I was trying to call the testupload() function from inside LRtasks..but we dont need to call it in separate task and the function works perfect

Connecting swift into web service

Hey guys I'm kinda new into swift programming, currently I'm making an iOS apps and facing a problem
I have one textfield and one textview in my view controller, I'm supposed to connect the application into a web service, so when I input number in the textfield, the apps will print the return value in the textview. But i don't know what to code in the Xcode to communicate the apps with the server.
This is the code of the web service
<?php error_reporting(E_ERROR | E_PARSE);
include 'koneksi.php';
$nama = $_REQUEST['nama'];
$query = ("select * from pegawai where nip='$nama' or no_kpe='$nama'");
$exe = mysql_query($query);
if($row = mysql_fetch_assoc($exe)){
$c = TRIM($row['nama']);
$a = NUMBER_FORMAT($row['tht']);
$b = NUMBER_FORMAT($row['pensiun']);
if($a == 0){
echo "Nama = ".$c."\n";
echo "THT = Sedang Dilakukan Peremajaan Data Keluarga"."\n";
echo "Pensiun = Rp. ".$b;
}
else{
echo "Nama = ".$c."\n";
echo "THT = Rp. ".$a."\n";
echo "Pensiun = Rp. ".$b;
}
}
else {
echo "Mohon Periksa Kembali Notas atau No. KPE anda."."\n";
}
?>
I'm using Xcode 7 and running the apps in iOS 9.0
I'm new in this language and also web service so step by step answer will be much appreciated
You need to use the NSURLSession API to connect to a remote web service. I suggest using AFNetworking. It is an easy to use framework that makes network request and serialization for you.

eajaxupload in yii failes

I try ti user eajaxupload extention in yii(using this article: http://www.yiiframework.com/extension/eajaxupload
I want Upload and attache image to one of controller,
I try this code:
in controller: *(my controller name is : article)*
public function actionUpload()
{
Yii::import("ext.EAjaxUpload.qqFileUploader");
$folder= Yii::app()->baseUrl .'/uploads';// folder for uploaded files
$allowedExtensions = array("jpg");//array("jpg","jpeg","gif","exe","mov" and etc...
$sizeLimit = 10 * 1024 * 1024;// maximum file size in bytes
$uploader = new qqFileUploader($allowedExtensions, $sizeLimit);
$result = $uploader->handleUpload($folder);
$result=htmlspecialchars(json_encode($result), ENT_NOQUOTES);
$fileSize=filesize($folder.$result['filename']);//GETTING FILE SIZE
$fileName=$result['filename'];//GETTING FILE NAME
//echo $result;// it's array
}
and in _form.php (for controller) i have:
$this->widget('ext.EAjaxUpload.EAjaxUpload',
array(
'id'=>'uploadFile',
'config'=>array(
'action'=>'/article/upload',
'allowedExtensions'=>array("jpg"),//array("jpg","jpeg","gif","exe","mov" and etc...
'sizeLimit'=>10*1024*1024,// maximum file size in bytes
//'minSizeLimit'=>10*1024*1024,// minimum file size in bytes
//'onComplete'=>"js:function(id, fileName, responseJSON){ alert(fileName); }",
'showMessage'=>"js:function(message){ alert(message); }"
)
)); ?>
upload folder have full access for all!,
but when i push upload file and select a file always get error: filename, filesize and Faild!
What is wrong in my code?
What do you see on the console when you you add this
echo "<pre>";
print_r($result);
echo "</pre>";exit(0);
after $result=htmlspecialchars(json_encode($result), ENT_NOQUOTES);
Make sure your upload folder exists. Yii::app()->baseUrl returns '...yourproject/protected'.
I use:$folder=Yii::app() -> getBasePath() . "/../images/";
Also check your console in browser(press F12). If you got 403 error, then add rules to your controller for upload action
public function accessRules()
{
return array(
array('allow', // allow all users to perform 'index' and 'view' actions
'actions'=>array('index','view','upload'),
'users'=>array('*'),
),
.....

Resources