} else { if ($max_user_attachment_space > 0 && $free_upload_space > -1 && $free_upload_space < $file_size) { @unlink($file_path); @unlink($temp_file); $valid = false; $error = gettext('You do not have enough free attachment space'); } else { $image_width = null; $image_height = null; $thumbnail = false; if (($image_info = @getimagesize($file_path)) !== false) { $image_width = $image_info[0]; $image_height = $image_info[1]; $thumbnail = image_resize($file_path, $file_path . '.thumb'); } if (($attachment_aid = attachments_add($_SESSION['UID'], $file_name, $file_hash, $file_type, $file_size, $image_width, $image_height, $thumbnail)) !== false) { $attachment_details = attachments_get_by_aid($attachment_aid, $_SESSION['UID']); } else { @unlink($file_path); @unlink($file_path . '.thumb'); @unlink($temp_file); $valid = false; $error = gettext('Attachment failed to upload. Please try again.'); } } } } $content = json_encode(array('error' => $error, 'attachment' => $attachment_details, 'preventRetry' => true, 'success' => $valid)); } } header(sprintf('Content-type: %s', $content_type));
$upload_not_allowed[] = $filename; if (@file_exists($temp_file)) { unlink($temp_file); } } else { if ($max_attachment_space > 0 && $users_free_space < $file_size) { $upload_failure[] = $filename; if (@file_exists($temp_file)) { unlink($temp_file); } } else { $unique_file_id = md5(uniqid(mt_rand())); $file_hash = md5("{$aid}{$unique_file_id}{$filename}"); $file_path = "{$attachment_dir}/{$file_hash}"; if (@move_uploaded_file($temp_file, $file_path)) { attachments_add($uid, $aid, $unique_file_id, $filename, $file_type); image_resize($file_path, $file_path . '.thumb'); if ($users_free_space > 0) { $users_free_space -= $file_size; } $upload_success[] = $filename; } else { if (@file_exists($temp_file)) { unlink($temp_file); } $upload_failure[] = $filename; } } } } }