Любая идея, почему патч не будет принимать загрузки файлов Multipart/Form-Data? Я пытаюсь обновить данные, используя данные формы mumultipart, но мой почтальон не распознает переменные, если я размещаю файл, он работает нормально. Ниже приведена моя функция в php < /p>
function updateImage($writeDB, $returned_userid) {
// Retrieve the record to be updated
$query = $writeDB->prepare('SELECT users.id, users.name, users.mobilenumber, users.profilepic from users where users.id=:userid');
$query->bindParam(':userid', $returned_userid, PDO::PARAM_INT);
$query->execute();
// get row count
$rowCount = $query->rowCount();
// make sure that the user exists for the given ID
if($rowCount === 0) {
// send JSON error response using function
sendResponse(404, false, "No user found to update");
}
// for each row returned - should be just one
while($row = $query->fetch(PDO::FETCH_ASSOC)) {
$image = new Image($row['id'], null, $row['name'], $row['mobilenumber'], $row['profilepic'], null, null, null, null, null, null, null, null);
}
// Update the record
$name = isset($_POST['name']) ? $_POST['name'] : null;
$filename = isset($_FILES['image']['name']) ? $_FILES['image']['name'] : null;
$tmp_name = isset($_FILES['image']['tmp_name']) ? $_FILES['image']['tmp_name'] : null;
if (!empty($name)) {
echo $name;
$image->setProfile($name);
}
if (!empty($filename) && !empty($tmp_name)) {
// Handle the image upload
move_uploaded_file($tmp_name, "uploads/$filename");
$image->setProfilePic("uploads/$filename");
}
// Update the database record
$query = $writeDB->prepare("UPDATE users SET profilepic = :profilepic WHERE id = :userid");
$query->bindParam(':profilepic', $image->getProfilePic());
$query->bindParam(':userid', $returned_userid, PDO::PARAM_INT);
$query->execute();
// Return the updated record
$record = array(
"id" => $image->getId(),
"name" => $image->getUsername(),
"mobilenumber" => $image->getMobileNo(),
"profilepic" => $image->getProfilePic()
);
header('Content-Type: application/json');
echo json_encode($record);
}
if(empty($_GET)){
$returned_userid = checkAuthStatusAndReturnUserID($writeDB);
switch($_SERVER['REQUEST_METHOD']){
case 'PATCH':
updateImage($writeDB, $returned_userid);
break;
}
}
< /code>
Следующий мой ответ почтальона Я пытаюсь распечатать переменную имени, но это всегда null < /p>
Подробнее здесь: https://stackoverflow.com/questions/756 ... -form-data
Запрос исправления не работает ⇐ Php
Кемеровские программисты php общаются здесь
1739351392
Anonymous
Любая идея, почему патч не будет принимать загрузки файлов Multipart/Form-Data? Я пытаюсь обновить данные, используя данные формы mumultipart, но мой почтальон не распознает переменные, если я размещаю файл, он работает нормально. Ниже приведена моя функция в php < /p>
function updateImage($writeDB, $returned_userid) {
// Retrieve the record to be updated
$query = $writeDB->prepare('SELECT users.id, users.name, users.mobilenumber, users.profilepic from users where users.id=:userid');
$query->bindParam(':userid', $returned_userid, PDO::PARAM_INT);
$query->execute();
// get row count
$rowCount = $query->rowCount();
// make sure that the user exists for the given ID
if($rowCount === 0) {
// send JSON error response using function
sendResponse(404, false, "No user found to update");
}
// for each row returned - should be just one
while($row = $query->fetch(PDO::FETCH_ASSOC)) {
$image = new Image($row['id'], null, $row['name'], $row['mobilenumber'], $row['profilepic'], null, null, null, null, null, null, null, null);
}
// Update the record
$name = isset($_POST['name']) ? $_POST['name'] : null;
$filename = isset($_FILES['image']['name']) ? $_FILES['image']['name'] : null;
$tmp_name = isset($_FILES['image']['tmp_name']) ? $_FILES['image']['tmp_name'] : null;
if (!empty($name)) {
echo $name;
$image->setProfile($name);
}
if (!empty($filename) && !empty($tmp_name)) {
// Handle the image upload
move_uploaded_file($tmp_name, "uploads/$filename");
$image->setProfilePic("uploads/$filename");
}
// Update the database record
$query = $writeDB->prepare("UPDATE users SET profilepic = :profilepic WHERE id = :userid");
$query->bindParam(':profilepic', $image->getProfilePic());
$query->bindParam(':userid', $returned_userid, PDO::PARAM_INT);
$query->execute();
// Return the updated record
$record = array(
"id" => $image->getId(),
"name" => $image->getUsername(),
"mobilenumber" => $image->getMobileNo(),
"profilepic" => $image->getProfilePic()
);
header('Content-Type: application/json');
echo json_encode($record);
}
if(empty($_GET)){
$returned_userid = checkAuthStatusAndReturnUserID($writeDB);
switch($_SERVER['REQUEST_METHOD']){
case 'PATCH':
updateImage($writeDB, $returned_userid);
break;
}
}
< /code>
Следующий мой ответ почтальона Я пытаюсь распечатать переменную имени, но это всегда null < /p>
Подробнее здесь: [url]https://stackoverflow.com/questions/75634919/patch-request-is-not-working-multipart-form-data[/url]
Ответить
1 сообщение
• Страница 1 из 1
Перейти
- Кемерово-IT
- ↳ Javascript
- ↳ C#
- ↳ JAVA
- ↳ Elasticsearch aggregation
- ↳ Python
- ↳ Php
- ↳ Android
- ↳ Html
- ↳ Jquery
- ↳ C++
- ↳ IOS
- ↳ CSS
- ↳ Excel
- ↳ Linux
- ↳ Apache
- ↳ MySql
- Детский мир
- Для души
- ↳ Музыкальные инструменты даром
- ↳ Печатная продукция даром
- Внешняя красота и здоровье
- ↳ Одежда и обувь для взрослых даром
- ↳ Товары для здоровья
- ↳ Физкультура и спорт
- Техника - даром!
- ↳ Автомобилистам
- ↳ Компьютерная техника
- ↳ Плиты: газовые и электрические
- ↳ Холодильники
- ↳ Стиральные машины
- ↳ Телевизоры
- ↳ Телефоны, смартфоны, плашеты
- ↳ Швейные машинки
- ↳ Прочая электроника и техника
- ↳ Фототехника
- Ремонт и интерьер
- ↳ Стройматериалы, инструмент
- ↳ Мебель и предметы интерьера даром
- ↳ Cантехника
- Другие темы
- ↳ Разное даром
- ↳ Давай меняться!
- ↳ Отдам\возьму за копеечку
- ↳ Работа и подработка в Кемерове
- ↳ Давай с тобой поговорим...
Мобильная версия