Не нравятся результаты поиска? Попробуйте другой поиск!
DLE FAQ » Все вопросы » Общие вопросы по PHP » как определить переменную?

как определить переменную?


     07.10.2014    PHP    Все вопросы » Общие вопросы по PHP    2297

вопрос
зада следующая: при загрузки фотографии переменная $aid не определяется

    $aid = intval($_GET['aid']);        
    $user_id = $user_info['user_id'];        


            
//Создаем альбом
$aname = 'Фотографии с моей страницы';
$adescr = '';
$alhash = md5(md5($server_time).$aname.$adescr.md5($user_info['user_id']).md5($user_info['user_email']).$_IP);
$date_create = date('Y-m-d H:i:s', $server_time);
$db->query("INSERT INTO `".PREFIX."_albums` (aid, user_id, name, descr, ahash, adate, position, privacy, editablea) VALUES ('{$aid}', '{$user_info['user_id']}','Фотографии с моей страницы', '', '{$alhash}', '{$date_create}', '0', '1|1', '1')");
$db->query("UPDATE `".PREFIX."_users` SET user_albums_num = user_albums_num+1 WHERE user_id = '{$user_info['user_id']}'");

//* Подключаем класс для фотографий *//
            
            include ENGINE_DIR.'/classes/images.php';
            
            
            //* Проверка на кол-во фоток в альбоме *//
                
if($row['photo_num'] < $config['max_album_photos']){
                                    
//* Если нет папки альбома, то создаём её *//                
$album_dir = ROOT_DIR.'/uploads/users/'.$user_id.'/albums/'.$aid.'/';
if(!is_dir($album_dir)){
@mkdir($album_dir, 0777);
@chmod($album_dir, 0777);
}
            
//* Разришенные форматы *//
            
            $allowed_files = array('jpg', 'jpeg', 'jpe', 'png', 'gif');

//* Получаем данные о фотографии *//
            
            $image_tmp = $_FILES['uploadfile']['tmp_name']; //* Оригинальное название для определения формата *//        
            $image_name = totranslit($_FILES['uploadfile']['name']); //* Имя фотографии *//        
            $image_rename = substr(md5($server_time+rand(1,100000)), 0, 15); //* Размер файла *//            
            $image_size = $_FILES['uploadfile']['size']; //* Формат файла *//            
            $type = end(explode(".", $image_name));

//* Проверяем если, формат верный то пропускаем *//
            
            if(in_array($type, $allowed_files)){
                if($image_size < 5000000){
                    $res_type = '.'.$type;
                    
//* Директория куда загружать *//                    
                    
                    if(move_uploaded_file($image_tmp, $album_dir.$image_rename.$res_type)) {
                    
//* Создание оригинала для стены *//
                        
                        $tmb = new thumbnail($album_dir.$image_rename.$res_type);
                        $tmb->size_auto(770);
                        $tmb->jpeg_quality(95);
                        $tmb->save($album_dir.'o_'.$image_rename.$res_type);

                        
//* Создание уменьшеной копии 50х50 *//
                        
                        $tmb = new thumbnail($album_dir.$image_rename.$res_type);
                        $tmb->size_auto('50x50');
                        $tmb->jpeg_quality(97);
                        $tmb->save($album_dir.'50_'.$image_rename.$res_type);
                        
//* Создание уменьшеной копии 100х100 *//
                        
                        $tmb = new thumbnail($album_dir.$image_rename.$res_type);
                        $tmb->size_auto('100x100');
                        $tmb->jpeg_quality(97);
                        $tmb->save($album_dir.'100_'.$image_rename.$res_type);
                        
//* Создание уменьшеной копии для обложки альбома 278x226 *//
                        
                        $tmb = new thumbnail($album_dir.$image_rename.$res_type);
                        $tmb->size_auto('278x226px');
                        $tmb->jpeg_quality(90);
                        $tmb->save($album_dir.'c_'.$image_rename.$res_type);
                        
                        $image_rename = $db->safesql($image_rename);
                        $res_type = $db->safesql($res_type);
                        
                            
//* Создание уменьшеной копии 182х182 *//
                        
                        $tmb = new thumbnail($album_dir.$image_rename.$res_type);
                        $tmb->size_auto('182x182');
                        $tmb->jpeg_quality(100);
                        $tmb->save($album_dir.'182_'.$image_rename.$res_type);

                        $image_rename = $db->safesql($image_rename);
                        $res_type = $db->safesql($res_type);
                        
                                $date = date('Y-m-d H:i:s', $server_time);
                                
//* Генерируем position фотки для "обзора фотографий" *//
                                
                                $position_all = $_SESSION['position_all'];
                                if($position_all){
                                    $position_all = $position_all+1;
                                    $_SESSION['position_all'] = $position_all;
                                } else {
                                    $position_all = 100000;
                                    $_SESSION['position_all'] = $position_all;
                                }


//Вставляем фотографию
$db->query("INSERT INTO `".PREFIX."_photos` (album_id, photo_name, user_id, date, position) VALUES ('{$aid}', '{$image_rename}{$res_type}', '{$user_id}', '{$date}', '{$position_all}')");

//* Проверяем на наличии обложки у альбома, если нету то ставим обложку загруженную фотку *//                            
if(!$row['cover'])
$db->query("UPDATE `".PREFIX."_albums` SET cover = '{$image_rename}{$res_type}' WHERE aid = '{$aid}'");
$db->query("UPDATE `".PREFIX."_albums` SET photo_num = photo_num+1, adate = '{$date}' WHERE aid = '$aid}'");
$img_url = $config['home_url'].'uploads/users/'.$user_id.'/albums/'.$aid.'/c_'.$image_rename.$res_type;
            } else
                        echo 'bad';
                } else
                    echo 'big_size';
                    } else
                    echo 'max_img';
            } else
                echo 'bad_format';
            die();
        break;
                        


Если нет папки альбома, то она создается автоматически, т.е из за того что переменная $aid у меня не определена создается папка 0, вместо случайных цифр

$album_dir = ROOT_DIR.'/uploads/users/'.$user_id.'/albums/'.$aid.'/';
if(!is_dir($album_dir)){
@mkdir($album_dir, 0777);
@chmod($album_dir, 0777);
}

в tpl файле прописал переменную $aid
action: '/index.php?go=albums&act=upload&aid={aid}',
переменная не определяется

<script type="text/javascript">
$(document).ready(function(){
    Xajax = new AjaxUpload('upload', {
        action: '/index.php?go=albums&act=upload&aid={aid}',
        name: 'uploadfile',
        onsubmit: function (file, ext) {
        if (!(ext && /^(jpg|png|jpeg|gif|jpe)$/.test(ext))) {
            Box.Info('load_photo_er', lang_dd2f_no, lang_bad_format, 400);
                return false;
            }
            butloading('upload', '113', 'disabled', '');
        },
        onComplete: function (file, response) {
            if(response == 'bad_format')
                $('.err_red').show().text(lang_bad_format);
            else if(response == 'big_size')
                $('.err_red').show().html(lang_bad_size);
            else if(response == 'bad')
                $('.err_red').show().text(lang_bad_aaa);
            else {
                Box.Close('photo');
                $('#ava').html('<img  class="ava_style" src="'+response+'" alt="" />');
                $('body, html').animate({scrollTop: 0}, 250);
                $('#del_pho_but').show();
            }
        }
    });
});
</script>

<div class="load_photo_pad">
<div class="err_red" style="display:none;font-weight:normal;"></div>
<div class="photo_bg_loassdadadd">  <img src="{ava_load}"  class="photo_bg_load" />
</div>


  <div class="photo_bg_load_text">
<h4>Зачем нужна фотография?</h4>
<p class="ta-l">
— Людям с реальной фотографией пишут чаще;
<br>
— Ваши друзья смогут легко узнать вас;
<br>
— Без фото вас не смогут найти и увидеть другие люди.
</p></div>
<div class="load_photo_but"><div class="button_div fl_l">
<button style="width: 192px;" id="upload">Выбрать фотографию</button></div>
</div>

Ответа пока нет


5 комментариев

lutskboy
Эксперт

lutskboy - 7 октября 2014 18:35 -

отключите чпу

wolf777
Юзер

wolf777 - 7 октября 2014 21:10 -

а ещё варианты есть?

lutskboy
Эксперт

lutskboy - 7 октября 2014 21:22 -

вариантов море. раз она не передается, значит вы ее не передаете
может вы ее методом POST передаете, а у вас проверка GET

wolf777
Юзер

wolf777 - 7 октября 2014 22:41 -

вот такие ошибки идут, как это исправить?
Uncaught TypeError: Cannot set property 'innerHTML' of null id1:6
Failed to load resource: the server responded with a status of 404 (Not Found) http://vm.su/uploads...e998c082030.jpg
Failed to load resource: the server responded with a status of 404 (Not Found) http://vm.su/uploads...41149761129.jpg
Failed to load resource: the server responded with a status of 404 (Not Found) http://vm.su/uploads...570fc48e717.jpg
Failed to load resource: the server responded with a status of 404 (Not Found) http://vm.su/uploads...9202012a126.jpg
Failed to load resource: the server responded with a status of 404 (Not Found) http://vm.su/uploads...22c5369fa85.jpg
Failed to load resource: the server responded with a status of 404 (Not Found) http://vm.su/uploads...15b8445b1ca.jpg
Failed to load resource: the server responded with a status of 404 (Not Found) http://vm.su/uploads...bbef39a2e47.jpg
Uncaught TypeError: Cannot set property 'innerHTML' of null id1:6
Failed to load resource: the server responded with a status of 404 (Not Found) http://vm.su/uploads...bbef39a2e47.jpg
Failed to load resource: the server responded with a status of 404 (Not Found)

wolf777
Юзер

wolf777 - 7 октября 2014 21:40 -

при создании альбома она передается, а при загрузки фотографии нет, а как проверить её в коде из за чего не определяется?

Чтобы комментировать - войдите или зарегистрируйтесь на сайте

Похожие вопросы

наверх