我正在使用Slim 3 PHP
将视频数据写入我的iOS
应用。由于某种原因,我在尝试将数据写入MySQL
数据库时收到错误。
我的视频端点只是我的视频端点没有问题。
我的代码如下:
function uploadEventVideo($req, $res, $args) {
global $db;
$user_id = validateUserAuthentication($req);
if($user_id) {
$files = $req->getUploadedFiles();
if (isset($files['media_photo'])) {
$media_photo_url = 'Photo_' . generateRandomString(40) . '.jpg';
$files['media_photo']->moveTo('assets/images/' . $media_photo_url);
} else {
$media_photo_url = '';
}
if (isset($files['media_video'])) {
$media_video_url = 'Video_' . generateRandomString(40) . '.mov';
$files['media_video']->moveTo('assets/videos/' . $media_video_url);
} else {
$media_video_url = '';
}
$query = $db->prepare('insert into tblEventMedia (media_user_id,
media_event_id,
media_photo_url,
media_video_url,
media_type)
values (:media_user_id,
:media_event_id,
:media_photo_url,
:media_video_url,
"VIDEO")');
$query->bindParam(':media_user_id', $user_id);
$query->bindParam(':media_event_id', $args['id']);
$query->bindParam(':media_photo_url', $media_photo_url);
$query->bindParam(':media_video_url', $media_video_url);
if($query->execute()) {
$query = $db->prepare('select * from tblEventMedia where media_id = :media_id');
$query->bindParam(':media_id', $db->lastInsertId());
if($query->execute()) {
$media = $query->fetch(PDO::FETCH_NAMED);
$media['media_is_read'] = true;
$newRes = makeResultResponseWithObject($res, 200, $media);
} else {
$newRes = makeResultResponseWithString($res, 400, $query->errorInfo()[2]);
}
} else {
$newRes = makeResultResponseWithString($res, 400, $query->errorInfo()[2]);
}
} else {
$newRes = makeResultResponseWithString($res, 401, 'Your token has expired. Please login again.');
}
return $newRes; }
答案 0 :(得分:1)
确保您的网络服务器可以写assets/images/
你在Ubuntu / Debian平台上托管,很可能会有效:
$ cd {root directory of your project}
$ mkdir -p assets/images
$ chgrp www-data assets/images
$ chmod g+rws assets/images