Php 正在上载文件,但名称为空
我有一个IOS应用程序,它使用PHP作为我的API。我的文件上传工作正常,但文件名没有附加到文件中。我已经在我的应用程序中镜像了其他页面,但它仍然不工作,尽管其他页面工作正常。我可以在服务器上看到该文件,但名称是notes-.jpg。它不是根据代码将puuid附加到名称。我在ViewController上实现了不起作用的MessageKit(以防万一)。下面是我的代码,我觉得我在大海捞针。代码有点草率(请不要判断) PHP上传文件Php 正在上载文件,但名称为空,php,json,swift,file-upload,Php,Json,Swift,File Upload,我有一个IOS应用程序,它使用PHP作为我的API。我的文件上传工作正常,但文件名没有附加到文件中。我已经在我的应用程序中镜像了其他页面,但它仍然不工作,尽管其他页面工作正常。我可以在服务器上看到该文件,但名称是notes-.jpg。它不是根据代码将puuid附加到名称。我在ViewController上实现了不起作用的MessageKit(以防万一)。下面是我的代码,我觉得我在大海捞针。代码有点草率(请不要判断) PHP上传文件 <?php if (!empty($_REQUEST["u
<?php
if (!empty($_REQUEST["uuid"])) {
$id = htmlentities($_REQUEST["id"]);
$recipient = htmlentities($_REQUEST["recipient"]);
$recipient_id = htmlentities($_REQUEST["recipient_id"]);
$uuid = htmlentities($_REQUEST["uuid"]);
$puuid = htmlentities($_REQUEST["puuid"]);
$text = htmlentities($_REQUEST["text"]);
$sender = htmlentities($_REQUEST["sender"]);
$sender_id = htmlentities($_REQUEST["sender_id"]);
if (isset($_FILES['file']) && $_FILES['file']['size'] > 1) {
$folder = "/home/xxxxx/public_html/notes/" . $uuid;
// if no posts folder, create it
if (!file_exists($folder)) {
mkdir($folder, 0777, true);
}
$picture = $folder . "/" . basename($_FILES["file"]["name"]);
chmod($picture,0777);
if (move_uploaded_file($_FILES["file"]["tmp_name"], $picture)) {
$path = "http://localhost/notes/" . $uuid . "/notes-" . $puuid . ".jpg";
$returnArray["message"] = "Post has been made with picture";
$returnArray["path"] = $path;
$returnArray["status"] = "200";
} else {
$returnArray["message"] = "Post has been made without picture";
$path = "";
}
$result=$access->insertMessage($recipient, $recipient_id, $uuid, $sender,$sender_id, $text, $path);
// STEP 2.5 If posts are found, append them to $returnArray
if (!empty($result)) {
$returnArray["message"] = $result;
$result = $access->updatebadge($recipient_id);
}
else {
$returnArray["message"] = "Couldnt insert". $puuid ."";
}
// if data is not passed - show posts except id of the user
}
else {
$username = htmlentities($_REQUEST["username"]);
$uuid = htmlentities($_REQUEST["uuid"]);
$recipient_id = htmlentities($_REQUEST["recipient_id"]);
$message = $access->conversation($username, $uuid, $recipient_id);
if (!empty($message)) {
$returnArray["message"] = $message;
}
}
}
$access->disconnect();
echo json_encode($returnArray);
?>
我想出来了。Swift中的正文和标题不正确,未发送正确的文件名 我把尸体改成:
// web development and MIME Type of passing information to the web server
let boundary = "Boundary-\(NSUUID().uuidString)"
request.setValue("multipart/form-data; boundary=\(boundary)", forHTTPHeaderField: "Content-Type")
// access / convert image to Data for sending to the server
var data = Data()
// if picture has been selected, compress the picture before sending to the server
if image != nil {
data = image.jpegData(compressionQuality: 0.5)!
}
// building the full body along with the string, text, file parameters
request.httpBody = Helper().body(with: parameters, filename: "notes-\(puuid).jpg", filePathKey: "file", imageDataKey: data, boundary: boundary) as Data
我想出来了。Swift中的正文和标题不正确,未发送正确的文件名 我把尸体改成:
// web development and MIME Type of passing information to the web server
let boundary = "Boundary-\(NSUUID().uuidString)"
request.setValue("multipart/form-data; boundary=\(boundary)", forHTTPHeaderField: "Content-Type")
// access / convert image to Data for sending to the server
var data = Data()
// if picture has been selected, compress the picture before sending to the server
if image != nil {
data = image.jpegData(compressionQuality: 0.5)!
}
// building the full body along with the string, text, file parameters
request.httpBody = Helper().body(with: parameters, filename: "notes-\(puuid).jpg", filePathKey: "file", imageDataKey: data, boundary: boundary) as Data
你能在服务器上找到上传的文件吗?你能在print()中找到文件名吗?@sayooj我能根据时间戳在服务器上找到文件。但是它的名字是notes-.jpg,它没有根据code@angel在createparams函数中,我得到了文件名,但在UploadImages中没有,这里调用的
htmlentities()
数量惊人。由于这些都与HTML显示转义无关,因此您根本不应该调用此函数。您是否能够在服务器中找到上载的文件?您可以在print()中获得文件名?@sayooj我可以根据时间戳在服务器上找到该文件。但是它的名字是notes-.jpg,它没有根据code@angel在createparams函数中,我得到了文件名,但在UploadImages中没有,这里调用的htmlentities()
数量惊人。由于所有这些都与HTML显示转义无关,所以根本不应该调用此函数。