Show Me How to Upload a text File From my SWIFT iOS app to PHP Using uploadTaskWithRequest

Tamamlanmış İlan edilme: 7 yıl önce Teslim sırasında ödenir
Tamamlanmış Teslim sırasında ödenir

Provide me the PHP code and Swift code for how to upload a text file from an app to a webserver using the uploadTaskWithRequest function.

Below is roughly what I have so far but it doesn't work. I get a successful response from the server but no file actually appears on the server or when I echo $_FILES its just blank.

lazy var config: NSURLSesionConfiguration = [login to view URL]()

lazy var session: NSURLSession = NSURLSession(configuration: [login to view URL], delgate: self, delegateQueue: [login to view URL]())

let phpURL = "[login to view URL]"

let uploadStringURL: NSURL = NSURL(string: phpURL)!

let uploadRequest = NSMutableURLRequest(URL: uploadStringURL)

let fileManager = [login to view URL]()

let docs = [login to view URL](.DocumentDirectory, inDomains: .userDomainMask).first

let fullFilePath = docs!/URLByAppendingPathComponent("[login to view URL]")

[login to view URL] = "POST"

let uploadTask = [login to view URL](uploadRequest, fromFile: fullFilePath, completionHandler: {(let data, let response, let error) in

})

[login to view URL]()

The uploadTask should be pushing the file to the server and it gets a response 200 showing that it was successful.

Here is the PHP part:

<?php

$target_dir = "/var/www/html/test-files/uploads";

$target_dir = $target_dir . "/" . basename($_FILES["file"]["name"]);

echo '{"target":'.$target_dir.'},';

echo '{"base":'.basename($_FILES["file"]["name"]).'}';

if (move_uploaded_file($_FILES["file"]["tmp_name"], $target_dir)) {

echo json_encode([

"Message" => "The file ". basename( $_FILES["file"]["name"]). " has been uploaded.",

"Status" => "OK"

]);

}

else {

echo json_encode([

"Message" => "Sorry, there was an error uploading your file.",

"Status" => "Error"

]);

}

?>

Uygulama Geliştiricisi PHP Swift

Proje NO: #10781683

Proje hakkında

2 teklif Uzak proje Aktif 7 yıl önce

Seçilen:

vaishakh22

iOS developer with 5+ years experience . Please check my recent reviews. I have good knowledge on php too. Please ping me for further details. Will get this working today itself

1 gün içinde %selectedBids___i_sum_sub_4%%project_currencyDetails_sign_sub_5% USD
(15 Değerlendirme)
5.5

Bu iş için 2 freelancer ortalamada $25 teklif veriyor

alpeshtk

I am Alpesh . I am experienced developer from India and I am interested in your project. I have 6+ years of experience on PHP Development and Web Development. I have good experience on PHP Development . I have reviewe Daha Fazla

1 gün içinde %bids___i_sum_sub_32%%project_currencyDetails_sign_sub_33% USD
(8 Değerlendirme)
2.9