function photos_swfu_upload in Album Photos 7.3
Same name and namespace in other branches
- 6.2 photos_swfu/photos_swfu.module \photos_swfu_upload()
Upload photos with SWFUpload.
1 string reference to 'photos_swfu_upload'
- photos_swfu_menu in photos_swfu/
photos_swfu.module - Implements hook_menu().
File
- photos_swfu/
photos_swfu.module, line 186
Code
function photos_swfu_upload($node = 0) {
if ($_GET['uid'] && $node) {
$query = db_select('users', 'u');
$query
->join('sessions', 's', 's.uid = u.uid');
$query
->fields('s', array(
'uid',
))
->fields('u', array(
'name',
))
->condition('s.sid', $_POST['PHPSESSID'])
->condition('s.hostname', ip_address());
$ac = $query
->execute()
->fetchObject();
if ($_GET['uid'] == $ac->uid) {
$ac->roles = array();
$ac->roles[DRUPAL_AUTHENTICATED_RID] = 'authenticated user';
$query = db_select('role', 'r');
$query
->join('users_roles', 'ur', 'ur.rid = r.rid');
$query
->fields('r', array(
'rid',
'name',
))
->condition('ur.uid', $_GET['uid']);
$result = $query
->execute();
foreach ($result as $role) {
$ac->roles[$role->rid] = $role->name;
}
$file = new stdClass();
if (node_access('update', $node, $ac) && $node->type == 'photos') {
$file->pid = $node->nid;
if ($_GET['nid']) {
$photo = node_load($_GET['nid']);
if (node_access('update', $photo, $ac)) {
$file->nid = $photo->nid;
}
else {
watchdog('photos_swfu', 'User do not have permission to update the node');
return header("HTTP/1.0 403.3 Internal Server Error");
}
}
}
else {
watchdog('photos_swfu', 'User do not have permission to update the node');
return header("HTTP/1.0 403.3 Internal Server Error");
}
if (is_uploaded_file($_FILES['Filedata']['tmp_name']) && !$_FILES['Filedata']['error']) {
$file->uri = file_destination(photos_check_path('default', '', $ac) . '/' . trim(basename(_photos_rename($_FILES['Filedata']['name']))), FILE_EXISTS_RENAME);
if (file_unmanaged_move($_FILES['Filedata']['tmp_name'], $file->uri)) {
$info = image_get_info($file->uri);
if ($info['extension'] && $info['width']) {
// @todo add limits?
// $limits = _upload_file_limits($ac);
/* $validators = array(
// 'file_validate_image_resolution' => array($limits['resolution']),
// '_file_validate_size' => array($limits['file_size'], $limits['user_size'], $ac)
); */
$file->uid = $ac->uid;
$file->filename = $_FILES['Filedata']['name'];
$file->filesize = $info['file_size'];
$file->filemime = $info['mime_type'];
if ($file->fid = _photos_save_data($file)) {
photos_image_date($file);
$output = 'File uploaded successfully!';
return $output;
}
}
else {
file_delete($file->uri);
watchdog('photos_swfu', 'Wrong file type');
return header("HTTP/1.0 403.3 Internal Server Error");
}
}
else {
watchdog('photos_swfu', 'Upload error. 2');
return header("HTTP/1.0 403.3 Internal Server Error");
}
}
else {
$error = '';
if ($_FILES['Filedata']['error'] == 1) {
$error = ' ' . t('Check file size and php.ini settings for upload_max_filesize.');
}
watchdog('photos_swfu', 'Upload error.' . $error);
return header("HTTP/1.0 403.3 Internal Server Error");
}
}
else {
watchdog('photos_swfu', 'Upload path may have been illegally modified');
return header("HTTP/1.0 530 Internal Server Error");
}
}
watchdog('photos_swfu', 'Album or user is not correct');
return header("HTTP/1.0 530 Internal Server Error");
}