www.webdeveloper.com
Results 1 to 3 of 3

Thread: i don't know what did gone wrong on but this is frustrating, plz help

  1. #1
    Join Date
    Aug 2012
    Posts
    5

    Angry i don't know what did gone wrong on but this is frustrating, plz help

    today i was working on a php script that uploads the images and makes a thumbnails out of them..
    well, i had the idea, i wrote the outline then i finished the script
    i had a couple of syntax errors and i fixed them,,

    but still there's some thing wrong with the code, no image was uploaded and no thumbnail created !!

    here's the code

    PHP Code:

    <?php
    ob_start
    ();
        function 
    create_thumbnail ($source$destination$thumb_width) { 
        
    $size getimagesize($source);
        
    $width $size[0]; 
        
    $height $size[1]; 
        
    $x 0
        
    $y 0;
        if (
    $width $height ) { 
            
    $x ceil (($width $height) / 2); 
            
    $width $height;}

        elseif (
    $height$width) { ]
            
    $y ceil (($height $width) / 2);
            
    $height $width; }

        
    $new_image imagecreatetruecolor($thumb_width,$thumb_width
                    or die (
    'Cannot intialize new image stream, make sure to read the instructions'); 
        
    $extension get_image_extension($source); 
        if(
    $extension=='jpg' || $extension=='jpeg'
            
    $image imagecreatefromjpeg($source); 
        if(
    $extension=='gif'// for gif
            
    $image imagecreatefromgif($source);
        if(
    $extension == 'png'// for png
            
    $image imagecreatefrompng($source);

            
    //now in relative to the upper lines the next few lines....

        
    imagecopyresampled($new_image,$image,0,0$x,$y,$thumb_width,$thumb_width,$width,$height);
        if(
    $extension=='jpg' || $extension=='jpeg')
            
    imagejpeg($new_image,$destination);
        if (
    $extension == 'gif')
            
    imagegif($new_image$destination);
        if(
    $extension=='png')
            
    imagepng($new_image,$destination);
        }

        function 
    get_image_extension($name) { // gets the image extension
            
    $name strtolower($name); // converts the name to lowercase
            
    $i strrpos($name"."); 
            if (!
    $i) {return ""; }
                
    $l strlen($name) - $i;
            
    $extension strlen($name,$i+1,$l);
            return 
    $extension
        }

        function 
    random_name($length) {
            
    $characters "ABCDEFGHIJKLMNOPQRSUVWXYZ0123456789";
            
    $name "";
            for (
    $i=0$i $length$i++) { 
            
    $name .= $characters [mt_rand(0strlen($characters) - 1)];    }
            return 
    "image-".$name;
        }


        
        
    $image_location "images/featured/"// images directory
        
    $thumbs_location "images/tn/"// thumnails directory
        
    $thumbs_width 100// width in pixels 
        
    $maximum_size 99999999999999// maximum size in kb (i know, but 99999999999999 looks pretty )
        
    $result ="click browse to locate the image you want to upload"// just a message bro.

        
    if (isset($_POST['submit'])){
            
            if(
    $_files['image']['name'] == "") { // checks
                
    $result "please choose an image !!";} // message


            
    else{ 
                
    $size=filesize($_FILES['image']['tmp_name']);
                
    $filename stripslashes($_FILES['image']['name']); 
                
    $extension get_image_extension($filename    ); 
                if (
    $size $maximum_size) { 
                    
    $result "image is too large, please choose a smaller one.";}

                else  
    // now checks the extension..
                    
    if (($extension != "jpg") &&     // not a jpg
                        
    ($extension != "jpeg") &&   // not a jpeg
                        
    ($extension != "png") &&   // not a png
                        
    ($extension != "gif")) {  // not a gif !! WTF is it ???
                        
    $result "it's not an image file, please choose an image with proper extension";}
                    
                    else  

                        
    $image_random_namerandom_name(15).".".$extension ;
                        
    $copy = @copy($_FILES['image']['tmp_name'], $images_location.$image_random_name);
                        if (!
    $copy) { $result "we're sorry, there's a technical error, please try again, please"; }

                     

                    else 
    // you finally reached this (else) and the image will be uploaded Hallelujah

                        
    create_thumbnail ($images_location.$image_random_name,$thumbs_location.$image_random_name$thumbs_width) ;
                         
    $result "image has been uploaded"// it actually refers to me
                    
    }
            }

        }
    echo 
    "$result";
    ?>

    <html>
        <head> 
            <title>Multi_uploader with thumbnails</title>
        </head>

    <body>
        <form action="multi_uploader_with_thumbnails.php" method="POST" encypte="multipart/form-data">
            <input type="hidden" name="MAX_FILE_SIZE" value="99999999999999"> <!-- this is kb but 99999999999999 looks cool --> 
            <input type="file" name="image" multiple="multiple" />
            <input name="submit" id="submit" type="submit" value="Upload them">
        </form>


    </body>
    </html>

    thanks in advance,

  2. #2
    Join Date
    Jun 2006
    Location
    Under your bed
    Posts
    357
    When I write a script, I normally write it a bit at a time because I test as I go along. The process: Write a little bit. Test. Fix problems (if any). Move on.

    Also, I check for more than just syntax errors, I check that the script is, thus far, working as I intended it.

    I do this because it's easier to find a bug in a little bit of code than it is in a whole wall of code where it could be hiding out anywhere.

    Hope this tip helps you in the future.

    As for what's wrong...I'm not going to attempt to answer because I am only an intermediate at PHP and there are advanced programmers here who can (and most likely will) answer. I try to stick to really simple problems because I'm more apt to give a good answer.
    The better I get at programming, the more I appreciate arrays. Handy dandy things they are.

  3. #3
    Join Date
    Aug 2004
    Location
    Ankh-Morpork
    Posts
    22,284
    Nothing immediately jumped out at me. My first suggestion would be to make sure you're seeing any/all debug info PHP might have for you:
    PHP Code:
    <?php
    ini_set
    ('display_errors'true);
    error_reporting(E_ALL);
    try {

    /* your code here, then */

    }
    catch(
    Exception $e) {
      echo 
    "<pre>".print_r($etrue)."</pre>";
    }
    "Well done....Consciousness to sarcasm in five seconds!" ~ Terry Pratchett, Night Watch

    How to Ask Questions the Smart Way (not affiliated with this site, but well worth reading)

    My Blog
    cwrBlog: simple, no-database PHP blogging framework

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center

"

"

X vBulletin 4.2.2 Debug Information

  • Page Generation 0.31660 seconds
  • Memory Usage 2,912KB
  • Queries Executed 15 (?)
More Information
Template Usage (33):
  • (1)SHOWTHREAD
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_global_above_footer
  • (1)ad_global_below_navbar
  • (1)ad_global_header1
  • (1)ad_global_header2
  • (1)ad_navbar_below
  • (1)ad_showthread_firstpost_sig
  • (1)ad_showthread_firstpost_start
  • (1)ad_thread_first_post_content
  • (1)ad_thread_last_post_content
  • (2)bbcode_php
  • (1)footer
  • (1)forumjump
  • (1)forumrules
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (1)headinclude_bottom
  • (3)memberaction_dropdown
  • (1)navbar
  • (4)navbar_link
  • (1)navbar_moderation
  • (1)navbar_noticebit
  • (1)navbar_tabs
  • (2)option
  • (3)postbit
  • (3)postbit_onlinestatus
  • (3)postbit_wrapper
  • (1)spacer_close
  • (1)spacer_open
  • (1)tagbit_wrapper 

Phrase Groups Available (6):
  • global
  • inlinemod
  • postbit
  • posting
  • reputationlevel
  • showthread
Included Files (26):
  • ./showthread.php
  • ./global.php
  • ./includes/class_bootstrap.php
  • ./includes/init.php
  • ./includes/class_core.php
  • ./includes/config.php
  • ./includes/functions.php
  • ./includes/functions_navigation.php
  • ./includes/class_friendly_url.php
  • ./includes/class_hook.php
  • ./includes/class_bootstrap_framework.php
  • ./vb/vb.php
  • ./vb/phrase.php
  • ./includes/functions_facebook.php
  • ./includes/functions_calendar.php
  • ./includes/functions_bigthree.php
  • ./includes/class_postbit.php
  • ./includes/class_bbcode.php
  • ./includes/functions_reputation.php
  • ./includes/functions_notice.php
  • ./packages/vbattach/attach.php
  • ./vb/types.php
  • ./vb/cache.php
  • ./vb/cache/db.php
  • ./vb/cache/observer/db.php
  • ./vb/cache/observer.php 

Hooks Called (70):
  • init_startup
  • friendlyurl_resolve_class
  • init_startup_session_setup_start
  • database_pre_fetch_array
  • database_post_fetch_array
  • init_startup_session_setup_complete
  • global_bootstrap_init_start
  • global_bootstrap_init_complete
  • cache_permissions
  • fetch_threadinfo_query
  • fetch_threadinfo
  • fetch_foruminfo
  • load_show_variables
  • load_forum_show_variables
  • global_state_check
  • global_bootstrap_complete
  • global_start
  • style_fetch
  • global_setup_complete
  • showthread_start
  • showthread_getinfo
  • strip_bbcode
  • friendlyurl_clean_fragment
  • friendlyurl_geturl
  • forumjump
  • cache_templates
  • cache_templates_process
  • template_register_var
  • template_render_output
  • fetch_template_start
  • fetch_template_complete
  • parse_templates
  • fetch_musername
  • notices_check_start
  • notices_noticebit
  • process_templates_complete
  • friendlyurl_redirect_canonical
  • showthread_post_start
  • showthread_query_postids
  • showthread_query
  • bbcode_fetch_tags
  • bbcode_create
  • showthread_postbit_create
  • postbit_factory
  • postbit_display_start
  • postbit_imicons
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • postbit_display_complete
  • memberaction_dropdown
  • tag_fetchbit_complete
  • forumrules
  • navbits
  • navbits_complete
  • build_navigation_data
  • build_navigation_array
  • check_navigation_permission
  • process_navigation_links_start
  • process_navigation_links_complete
  • set_navigation_menu_element
  • build_navigation_menudata
  • build_navigation_listdata
  • build_navigation_list
  • set_navigation_tab_main
  • set_navigation_tab_fallback
  • navigation_tab_complete
  • fb_like_button
  • showthread_complete
  • page_templates