View Single Post
  #24  
Old 02-02-2014, 04:47 PM
Action-N's Avatar
Action-N Action-N is offline
 
Join Date: Jan 2002
Location: Pasco, WA
Posts: 225
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Another status update. Been working on getting image type working, finally got it to add an update into the database. Then when it come time to attach to a section, stupified. Think what I worked on the week before was not the way to go.

I keep breaking the code an spend days trying to figure out what I did. My advice to anyone developing a mod backup your files before a session or attempt to change something around.

Once I figure out what I messed up this time I will post some code to get help with something. On my add/edit form the additional photos input still sends an empty array when nothing was entered in the input field, then once the array is processed breaks since it doesn't find any info. Probably a simple conditional to check for if incoming is empty but I tried that in a few spots an it just skips to the next error check.

--------------- Added [DATE]1391369191[/DATE] at [TIME]1391369191[/TIME] ---------------

Okay here is the bit of code from saving additional photos. As mentioned I added the " AND $image_ext != '' " to the first error I get and it gets me to the file upload error. It still uploads the photos that where submitted through the input field, so the error is from it going to the next number in the array. I'm stumped, an could use some help. Might even be as simple as taking out the error redirects.


Code:
    // Manage additional photos
    if ($_FILES['photoname'])
    {    
        $files = array();
        foreach ($_FILES['photoname'] as $k => $l)
        {
            foreach ($l as $i => $v)
            {
                if (!array_key_exists($i, $files))
                {
                    $files[$i] = array();
                }
                $files[$i][$k] = $v;
            }
        }

        // Counter for Titles
        $counter = 0;
        foreach ($files as $file)
        {
            // Get image name
            $imagename = @basename($file['name']);
            
            // Image name of temp uploaded photo
            //$tmp_imagename = realpath($vbulletin->options['vbrides_photo_path']) . '/tmp/' . @basename($file['tmp_name']);
            //echo $tmp_imagename;

            // Check image extention an make it lowercase
            $image_ext = strtolower(end(explode(".", $file['name'])));
            $allowed_exts = explode(', ', $vbulletin->options['vbrides_photo_exts']);
            if (!@in_array($image_ext, $allowed_exts) AND $image_ext != '')
            {
                $vbulletin->url="vbrides_usercp.php?" . $vbulletin->session->vars['sessionurl'] . "do=addedit&rideid=$rideid";
                eval(print_standard_redirect('vbrides_invalid_data_ext', true, true));
            }

            // Destination imagename, rename if set to
            if ($vbulletin->options['vbrides_photo_rename'])
            {
                $dest_imagename = md5(uniqid(rand(), true)) . '.' . $image_ext;
            } else {
                $dest_imagename = $imagename . '.' . $image_ext;
            }
        
            // Get size
            $imagesize = intval($file["size"]); // filesize($tmp_imagename);
            // Make sure file size is ok
            $maxsize = $vbulletin->options['vbrides_photo_size'];
            if ($maxsize > 0 && $maxsize*1024 < $imagesize)
            {
                $vbulletin->url="vbrides_usercp.php?" . $vbulletin->session->vars['sessionurl'] . "do=addedit&rideid=$rideid";
                eval(print_standard_redirect('vbrides_invalid_data_size', true, true));
            }
            
            // Upload the full image first
            $new_image = $photodir . 'full/' . $dest_imagename;

            if (!@move_uploaded_file($file['tmp_name'] , $new_image))
            {
                $vbulletin->url="vbrides_usercp.php?" . $vbulletin->session->vars['sessionurl'] . "do=addedit&rideid=$rideid";
                eval(print_standard_redirect('vbrides_invalid_data_upload', true, true));
            } else {
                // Resize photo
                // Get current size
                list($width, $height) = getimagesize($new_image);

                // Size thumb photo
                $photo_thumb_size = photoResize($width,$height,$vbulletin->options['vbrides_thumb_width']);
                $thumb_width = $photo_thumb_size['0'];
                $thumb_height = $photo_thumb_size['1'];
                createImage($width,$height,$thumb_width,$thumb_height,$image_ext,$new_image,$thumbdir,$dest_imagename,$vbulletin->options['vbrides_photo_quality']);
                
                $counter ++;
                $is_image = getimagesize($new_image);
                if (!$is_image)
                {
                    // Uninstall photo from ride photo directories
                    if(file_exists($photodir . "$dest_imagename")) unlink($photodir . "$dest_imagename");
                    if(file_exists($photodir . 'thumb/' . "$dest_imagename")) unlink($photodir . 'thumb/' ."$dest_imagename");
                    if(file_exists($photodir . 'full/' . "$dest_imagename")) unlink($photodir . 'full/' ."$dest_imagename");
                } else {
                    // Get title & type
                    $title = $db->escape_string($vbulletin->GPC["phototitle"][$counter]);
                    $type = $db->escape_string($vbulletin->GPC["phototype"][$counter]);

                    // Insert new photo
                    $db->query_write("UPDATE ".TABLE_PREFIX."vbrides_rides SET photos=photos+1 WHERE id = $rideid");
                    $db->query_write("INSERT INTO ".TABLE_PREFIX."vbrides_photos SET rideid = '$rideid', photoname = '$dest_imagename', title = '$title', type = '$type'");
                    $photoid = $vbulletin->GPC['id'] = $db->insert_id();
                }
            }
        }
    }
Reply With Quote
 
X vBulletin 3.8.12 by vBS Debug Information
  • Page Generation 0.01206 seconds
  • Memory Usage 1,801KB
  • Queries Executed 11 (?)
More Information
Template Usage:
  • (1)SHOWTHREAD_SHOWPOST
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_header_end
  • (1)ad_header_logo
  • (1)ad_navbar_below
  • (1)bbcode_code
  • (1)footer
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (6)option
  • (1)post_thanks_box
  • (1)post_thanks_button
  • (1)post_thanks_javascript
  • (1)post_thanks_navbar_search
  • (1)post_thanks_postbit_info
  • (1)postbit
  • (1)postbit_onlinestatus
  • (1)postbit_wrapper
  • (1)spacer_close
  • (1)spacer_open 

Phrase Groups Available:
  • global
  • postbit
  • reputationlevel
  • showthread
Included Files:
  • ./showpost.php
  • ./global.php
  • ./includes/init.php
  • ./includes/class_core.php
  • ./includes/config.php
  • ./includes/functions.php
  • ./includes/class_hook.php
  • ./includes/modsystem_functions.php
  • ./includes/functions_bigthree.php
  • ./includes/class_postbit.php
  • ./includes/class_bbcode.php
  • ./includes/functions_reputation.php
  • ./includes/functions_post_thanks.php 

Hooks Called:
  • init_startup
  • init_startup_session_setup_start
  • init_startup_session_setup_complete
  • cache_permissions
  • fetch_postinfo_query
  • fetch_postinfo
  • fetch_threadinfo_query
  • fetch_threadinfo
  • fetch_foruminfo
  • style_fetch
  • cache_templates
  • global_start
  • parse_templates
  • global_setup_complete
  • showpost_start
  • bbcode_fetch_tags
  • bbcode_create
  • postbit_factory
  • showpost_post
  • postbit_display_start
  • post_thanks_function_post_thanks_off_start
  • post_thanks_function_post_thanks_off_end
  • post_thanks_function_fetch_thanks_start
  • post_thanks_function_fetch_thanks_end
  • post_thanks_function_thanked_already_start
  • post_thanks_function_thanked_already_end
  • fetch_musername
  • postbit_imicons
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • postbit_display_complete
  • post_thanks_function_can_thank_this_post_start
  • showpost_complete