[5089] | 1 | <?php |
---|
| 2 | define('PHPWG_ROOT_PATH','../../../'); |
---|
| 3 | define('IN_ADMIN', true); |
---|
| 4 | |
---|
| 5 | $_COOKIE['pwg_id'] = $_POST['session_id']; |
---|
| 6 | |
---|
| 7 | include_once(PHPWG_ROOT_PATH.'include/common.inc.php'); |
---|
| 8 | include_once(PHPWG_ROOT_PATH.'admin/include/functions.php'); |
---|
| 9 | include_once(PHPWG_ROOT_PATH.'admin/include/functions_upload.inc.php'); |
---|
| 10 | |
---|
[5195] | 11 | check_pwg_token(); |
---|
[5089] | 12 | |
---|
| 13 | ob_start(); |
---|
[6625] | 14 | echo '$_FILES'."\n"; |
---|
[5089] | 15 | print_r($_FILES); |
---|
[6625] | 16 | echo '$_POST'."\n"; |
---|
[5089] | 17 | print_r($_POST); |
---|
[6625] | 18 | echo '$user'."\n"; |
---|
[5089] | 19 | print_r($user); |
---|
| 20 | $tmp = ob_get_contents(); |
---|
| 21 | ob_end_clean(); |
---|
[11963] | 22 | // error_log($tmp, 3, "/tmp/php-".date('YmdHis').'-'.sprintf('%020u', rand()).".log"); |
---|
[5089] | 23 | |
---|
[6625] | 24 | if ($_FILES['Filedata']['error'] !== UPLOAD_ERR_OK) |
---|
| 25 | { |
---|
| 26 | $error_message = file_upload_error_message($_FILES['Filedata']['error']); |
---|
| 27 | |
---|
| 28 | add_upload_error( |
---|
| 29 | $_POST['upload_id'], |
---|
| 30 | sprintf( |
---|
| 31 | l10n('Error on file "%s" : %s'), |
---|
| 32 | $_FILES['Filedata']['name'], |
---|
| 33 | $error_message |
---|
| 34 | ) |
---|
| 35 | ); |
---|
| 36 | |
---|
| 37 | echo "File Size Error"; |
---|
| 38 | exit(); |
---|
| 39 | } |
---|
| 40 | |
---|
| 41 | ob_start(); |
---|
| 42 | |
---|
[5089] | 43 | $image_id = add_uploaded_file( |
---|
| 44 | $_FILES['Filedata']['tmp_name'], |
---|
| 45 | $_FILES['Filedata']['name'], |
---|
[11962] | 46 | array($_POST['category_id']), |
---|
| 47 | $_POST['level'] |
---|
[5089] | 48 | ); |
---|
| 49 | |
---|
| 50 | if (!isset($_SESSION['uploads'])) |
---|
| 51 | { |
---|
| 52 | $_SESSION['uploads'] = array(); |
---|
| 53 | } |
---|
| 54 | |
---|
| 55 | if (!isset($_SESSION['uploads'][ $_POST['upload_id'] ])) |
---|
| 56 | { |
---|
| 57 | $_SESSION['uploads'][ $_POST['upload_id'] ] = array(); |
---|
| 58 | } |
---|
| 59 | |
---|
| 60 | array_push( |
---|
| 61 | $_SESSION['uploads'][ $_POST['upload_id'] ], |
---|
| 62 | $image_id |
---|
| 63 | ); |
---|
| 64 | |
---|
[11962] | 65 | $query = ' |
---|
| 66 | SELECT |
---|
| 67 | id, |
---|
| 68 | path, |
---|
| 69 | tn_ext |
---|
| 70 | FROM '.IMAGES_TABLE.' |
---|
| 71 | WHERE id = '.$image_id.' |
---|
| 72 | ;'; |
---|
| 73 | $image_infos = pwg_db_fetch_assoc(pwg_query($query)); |
---|
| 74 | |
---|
| 75 | $thumbnail_url = preg_replace('#^'.PHPWG_ROOT_PATH.'#', './', get_thumbnail_url($image_infos)); |
---|
| 76 | |
---|
| 77 | $return = array( |
---|
| 78 | 'image_id' => $image_id, |
---|
| 79 | 'category_id' => $_POST['category_id'], |
---|
| 80 | 'thumbnail_url' => $thumbnail_url, |
---|
| 81 | ); |
---|
| 82 | |
---|
[6625] | 83 | $output = ob_get_contents(); |
---|
| 84 | ob_end_clean(); |
---|
| 85 | if (!empty($output)) |
---|
| 86 | { |
---|
| 87 | add_upload_error($_POST['upload_id'], $output); |
---|
[11962] | 88 | $return['error_message'] = $output; |
---|
[6625] | 89 | } |
---|
| 90 | |
---|
[11962] | 91 | echo json_encode($return); |
---|
[5089] | 92 | ?> |
---|