Register

If this is your first visit, please click the Sign Up now button to begin the process of creating your account so you can begin posting on our forums! The Sign Up process will only take up about a minute of two of your time.

Results 1 to 2 of 2
  1. #1
    Junior Member
    Join Date
    Feb 2012
    Posts
    1
    Member #
    30754
    Hello there,

    I am quite new to PHP and I am engage with a project where by I need to develop a student database system. I am having problem students photo upload coding.

    Here's the code I have:

    Code for the form:
    PHP Code:
    <?php if (!isset($_POST['btnSubmit'])) { ?>
    <form action="index.php?view=create" method="post" enctype="multipart/form-data">
        <fieldset>
        <div>
                <label><b>Title:</b></label>

                <input name="album[title]" size="40" type="text" value="" class="textfield" />
                </div>

                <div>
              <label><b>Fullname</b></label>
              <input name="album[fullname]" size="40" type="text" value="" class="textfield" />
                </div>

                <div>

              <label><b>Attach Photo</b> </label>
                    <input type="hidden" name="" value="" />
    <?php
        $num 
    0;
        while(
    $num $num_uploads)
        {
            echo 
    '<div><input name="userfile[]" type="file" /></div>';
            
    $num++;
        }
    ?>
    And here's code for the php script which processing the upload:
    PHP Code:
    //If form was submitted
        
    if (isset($_POST['btnSubmit'])) {

        
    create_album($_POST['album']);
        
    $find_album_id mysql_insert_id();

            
    /*** check if a file has been submitted ***/
            
    if(isset($_FILES['userfile']['tmp_name']))
            {
                
    /** loop through the array of files ***/
                
    for($i=0$i count($_FILES['userfile']['tmp_name']);$i++)
                {

                  
    $ext strrchr($imgName".");

                  
    // then create a new random name
                  
    $newName md5(rand() * time()) . $ext;

                          if (
    is_image_types($_FILES['userfile']['type'][$i])
                          and 
    is_valid_file_size($_FILES['userfile']['size'][$i])
                          and 
    is_uploaded_file($_FILES['userfile']['tmp_name'][$i])
                          and 
    is_valid_width_height($_FILES['userfile']['tmp_name'][$i])
                      )
                      {

                          
    mysql_query("INSERT INTO images(name, album_id) VALUES('$newName', '$find_album_id')") ;
                          
    copy($_FILES['userfile']['tmp_name'][$i], './photos/'.$original_dir.'/' .$newName.'.jpg');

                }

                else
                {
            
    $warning "Click back error uploading file.
                                Please make sure your file is a JPEG and less than 1MB"
    ;
                }
            }
        }

        }

        break;

    I have the undefined variable notice for "$num_uploads" when I am trying to run the 'form' code. I wish to know how can I troubleshoot it or how I defined the variable. Thanks in advance.

  2.  

  3. #2
    WDF Staff mlseim's Avatar
    Join Date
    Apr 2004
    Location
    Cottage Grove, Minnesota
    Posts
    7,717
    Member #
    5580
    Liked
    718 times
    First of all, notices and warnings can be suppressed (fatal errors cannot).
    But instead of just "hiding" notices and warnings, the script is telling
    you that the script has no value when you're trying to use it.

    So where are you telling it the number of uploads?
    while($num < $num_uploads)



Remove Ads

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
All times are GMT -6. The time now is 12:37 PM.
Powered by vBulletin® Version 4.2.3
Copyright © 2019 vBulletin Solutions, Inc. All rights reserved.
vBulletin Skin By: PurevB.com