I am using Slim 3 PHP
to write video data to my iOS
app. for some reason I receive an error when trying to write the data to my MySQL
database.
I have no issue with my image endpoint just my video endpoint.
My code is as follows:
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; }
Ensure that assets/images/
is writable by your webserver
In you're hosting on a Ubuntu/Debian platform, most likely this will work:
$ cd {root directory of your project}
$ mkdir -p assets/images
$ chgrp www-data assets/images
$ chmod g+rws assets/images
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With