Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    New Coder
    Join Date
    Feb 2006
    Posts
    64
    Thanks
    0
    Thanked 0 Times in 0 Posts

    incorporating simple upload into current form

    i have this form here which captures event details. i'm missing a field that uploads a file. i have a script that does simple upload, but am unable to merge it together. please assist if possible.

    PHP Code:
    <?php
    //opens database
    include("../lib/db_connect.php");
                        
                
    $link = @mysql_connect("localhost"$user$pass);    
                if (!
    $link)
                    die (
    "Couldn't connect to MySQL");
                
    mysql_select_db($db$link)
                    or die (
    "Couldn't open $db".mysql_error());
                    
                
    //--------------------------------------------------------------------------
                //sql statement for programme category select list    
                
    $progcatselect "SELECT progcatname FROM progcat ORDER BY progcatname ASC";
                
    //exe sql for result
                
    $progcat_result mysql_query($progcatselect,$link
                    or die(
    "Couldn't execute query 0."); 
                
    //initiates values into the droplist
                
    $catoption_block .= "<OPTION value=``>Please select</OPTION>"
                while (
    $row mysql_fetch_array($progcat_result)) 
                { 
                    
    $progcatname $row["progcatname"]; 
                    
    $catoption_block .= "<OPTION value=`".$row[0]."`>".$row[0]."</OPTION>"
                }    
                
    //end of getting programme category list
                //--------------------------------------------------------------------------
                
                //--------------------------------------------------------------------------
                //sql statement for training level select list
                
    $trglvlselect "SELECT trglvlname FROM trglvl ORDER BY trglvlcode ASC";
                
    //exe sql for result
                
    $trglvl_result mysql_query($trglvlselect$link)
                    or die(
    "Couldn't execute query 1.");
                
    //initiates values into the droplist
                
    $trglvloption_block .="<OPTION value=``>Please select</OPTION>";
                while (
    $row mysql_fetch_array($trglvl_result))
                {
                    
    $trglvlname $row["trglvlname"];
                    
    $trglvloption_block .="<OPTION value=`".$row[0]."`>".$row[0]."</OPTION>";
                }
                
    //end of getting training level list
                //--------------------------------------------------------------------------
                
                //--------------------------------------------------------------------------
                //sql statement for cert select list
                
    $certselect "SELECT certname FROM cert ORDER BY certname ASC";
                
    //exe sql for result
                
    $cert_result mysql_query($certselect$link)
                    or die(
    "Couldn't execute query 2.");
                
    //initiates values into the droplist
                
    $certoption_block .="<OPTION value=``>Please select</OPTION>";
                while (
    $row mysql_fetch_array($cert_result))
                {
                    
    $cert $row["certname"];
                    
    $certoption_block .="<OPTION value=`".$row[0]."`>".$row[0]."</OPTION>";
                }
                
    //end of getting cert list
                //--------------------------------------------------------------------------
                
                //sql statement for organiser select list
                
    $organiserselect "SELECT clientName FROM client ORDER BY clientName ASC";
                
    //exe sql for result
                
    $organiser_result mysql_query($organiserselect$link)
                or die(
    "Couldn't execute query 3.");
                
    //initiates values into the droplist
                
    $organiseroption_block .="<OPTION value=``>Please select</OPTION>";
                while (
    $row mysql_fetch_array($organiser_result))
                {
                    
    $organiser $row["clientName"];
                    
    $organiseroption_block .="<OPTION value=`".$row[0]."`>".$row[0]."</OPTION>";
                }
                
    // end of getting organiser list
                //--------------------------------------------------------------------------
                
                //--------------------------------------------------------------------------
                //sql statement for collab select list
                
    $collabselect "SELECT clientName FROM client ORDER BY clientName ASC";
                
    //exe sql for result
                
    $collab_result mysql_query($collabselect$link)
                or die(
    "Couldn't execute query 4.");
                
    //initiates values into the droplist
                
    $collaboption_block .="<OPTION value=``>Please select</OPTION>";
                while (
    $row mysql_fetch_array($collab_result))
                {
                    
    $collab $row["clientName"];
                    
    $collaboption_block .="<OPTION value=`".$row[0]."`>".$row[0]."</OPTION>";
                }
                
    //end of getting collab list
                //--------------------------------------------------------------------------
                
                //--------------------------------------------------------------------------
                //sql statement for series select list
                
    $seriesselect "SELECT seriesname FROM eventseries ORDER BY seriesname ASC";
                
    //exe sql for result 
                
    $series_result mysql_query($seriesselect$link)
                or die(
    "Couldn't execute query 5.");
                
    //initiates values into the droplist
                
    $seriesoption_block .="<OPTION value=``>Please select</OPTION>";
                while (
    $row mysql_fetch_array($series_result))
                {
                    
    $series $row["seriesname"];
                    
    $seriesoption_block .="<OPTION value=`".$row[0]."`>".$row[0]."</OPTION>";
                }
                
    // end of getting series list
                //--------------------------------------------------------------------------
                
                //--------------------------------------------------------------------------
                //sql statement for venue select list
                
    $venueselect "SELECT venueName, roomName FROM venue ORDER BY venuename ASC";
                
    //exe sql for result
                
    $venue_result mysql_query($venueselect$link)
                or die(
    "Couldn't execute query 6.");
                
    //initiates values into the droplist
                
    $venueoption_block .="<OPTION value=``>Please select</OPTION>";
                while (
    $row mysql_fetch_array($venue_result))
                {
                    
    $venue $row["venueName"];
                    
    $venueoption_block .="<OPTION value=`".$row['venueName'].", ".$row['roomName']."`>".$row['venueName'].", ".$row['roomName']."</OPTION>";
                }
                
    //end of gettin venue list
                //--------------------------------------------------------------------------
                
                //--------------------------------------------------------------------------
                //sql statement for status select list
                
    $statusselect "SELECT statusName FROM eventstatus ORDER BY statusName ASC";
                
    //exe sql for result
                
    $status_result mysql_query($statusselect$link)
                or die(
    "Couldn't execute query 7.");
                
    //initiates values into the droplist
                
    $statusoption_block .="<OPTION value=``>Please select</OPTION>";
                while (
    $row mysql_fetch_array($status_result))
                {
                    
    $status $row["statusName"];
                    
    $statusoption_block .="<OPTION value=`".$row[0]."`>".$row[0]."</OPTION>";
                }
                
    //end of gettin status list
                //--------------------------------------------------------------------------
                
                //--------------------------------------------------------------------------
                //sql statement for event list
                
    $eventoption_block .= "<OPTION value=`0`> This is not a module of another Event </OPTION>"
                
    $eventselect "SELECT * FROM event WHERE sessionOf=0 ORDER BY mainTitle ASC";
                
    //exe sql for result
                
    $event_result mysql_query($eventselect,$link
                    or die(
    "Couldn't execute query 1."); 
                
    //initiates values into the droplist
                
    $eventoption_block .= "<OPTION value=``>Please select</OPTION>"
                while (
    $row mysql_fetch_array($event_result)) 
                {     
                    
    $mainTitle $row["mainTitle"];
                    
    $eventCode $row["eventCode"];
                    
    $eventoption_block .= "<OPTION value=`".$eventCode."`>".$mainTitle."</OPTION>"
                }    
                
    //end of getting event list
            
    ?>


    <form action="eventadded.php" method="post" enctype="multipart/form-data" name="eventreg">
        <table width="85%" border="0" align="center" cellpadding="4" cellspacing="0">
            <tr>
                <td colspan="2"><p class="style2">Add Event Details</p>
                </td>
            </tr>
            <tr>
              <td width="25%" class="style31">&nbsp;</td>
              <td><div align="right"><span class="style31">Event is Module Of</span>                <select name="sessionOf" id="sessionOf">
                <?php echo "$eventoption_block"?>
                </select>
              </div></td></tr>
            <tr>
              <td>&nbsp;</td>
              <td>&nbsp;</td>
          </tr>
            <tr>
                <td><span class="style31">Organiser Name:</span>
                </td>
                <td><select name="clientName" id="select"><?php echo "$organiseroption_block"?>
                </select><span class="style13">*</span> 
                </td>
            </tr>
            <tr>
                <td><span class="style31">Event Title:</span>
                </td>
                <td width="75%"><input name="mainTitle" type="text" id="mainTitle" size="50">
                <span class="style13">*</span>
                </td>
            </tr>
            <tr>
                <td><span class="style31">Event Sub Title 1:</span>
                </td>
                <td><input name="eventSub1" type="text" id="eventSub1" size="50">
                </td>
            </tr>
            <tr>
                <td><span class="style31">Event Sub Title 2:</span>
                </td>
                <td><input name="eventSub2" type="text" id="eventSub2" size="50">
                </td>
            </tr>
            <tr>
                <td><span class="style31">Event Sub Title 3:</span>
                </td>
                <td><input name="eventSub3" type="text" id="eventSub3" size="50">
                </td>
            </tr>
            <tr>
              <td><span class="style31">Event Description:</span> </td>
              <td><textarea name="trainDes" cols="50" rows="8" id="textarea"></textarea>
              </td>
          </tr>
            <tr>
                <td><span class="style31">Event Series:</span>
                </td>
                <td><select name="eventseries" id="eventseries"><?php echo "$seriesoption_block"?></select>
                </td>
            </tr>
            <tr>
                <td><span class="style31">Start Date:</span>
                </td>
                <td><input name="startDate" type="text" id="startDate" size=20 onBlur="setendDate()">
                    <span class="style17"><small><a href="javascript:showCal('Calendar4')">
                    Select starting date</a></small></span><span class="style18">*</span>
                </td>
            </tr>
               <tr>
                <td><span class="style31">Start Time:</span>
                </td>
                <td><input name="startTimeHr" type="text" id="startTimeHr" size="10" ><span class="style24">(HH)</span>
                    <input name="startTimeMin" type"text" id="startTimeMin" size="10"> <span class="style24">(MM)</span>
                </td>
            </tr>
            <tr> 
                <td><span class="style31">End Date:</span>
                </td>
                <td><input name="endDate" type="text" id="endDate" size=20 onBlur="datecheck()"> 
                    <span class="style17"><small><a href="javascript:showCal('Calendar5')">
                    Select ending date</a></small></span>
                </td>
            </tr>
            <tr>
                <td><span class="style31">End Time:</span>
                </td>
                <td><input name="endTimeHr" type="text" id="endTimeHr" size="10"> <span class="style24">(HH)</span>
                    <input name="endTimeMin" type="text" id="endTimeMin" size="10"> <span class="style24">(MM)</span>
                </td>
            </tr>
            <tr>
                <td><span class="style31">Event Venue:</span>
                </td>
                <td><select name="venue" id="venue"><?php echo "$venueoption_block"?>
                     </select> <span class="style13">*</span> <a href='../settings/addvenue.php'><span class=style6></span></a>
                </td>
            </tr>
            <tr>
                <td><span class="style31">Event Duration:</span>
                </td>
                 <td><input name="eventDurationHr" type="text" id="eventDuration" size="10" maxlength="50"><span class="style25">(HH)</span>
                   <input name="eventDurationMin" type="text" id="eventDuration" size="10" maxlength="50"><span class="style25">(MM)</span>
                <span class="style25">*</span> </td>
            </tr>
            <tr>
              <td><span class="style31">Modes of Payment :</span> </td>
              <td><input name="pay_credit_on" type="checkbox" id="pay_credit_on" value="yes" checked>
                <span class="style33">Credit Card Online
                <input name="pay_credit_off" type="checkbox" id="pay_credit_off" value="yes" checked>
                Credit Card Offline 
                <input name="pay_cheque" type="checkbox" id="pay_cheque" value="yes" checked>
    Cheque
    <input name="pay_giroDDA" type="checkbox" id="pay_giroDDA" value="yes" checked> 
    GIRO-DDA
    <input name="pay_giroIBG" type="checkbox" id="pay_giroIBG" value="yes" checked>
    GIRO-IBG
    <input name="pay_TT" type="checkbox" id="pay_TT" value="yes" checked>
    TT</span><span class="style33">

                <input name="pay_cash" type="checkbox" id="pay_cash" value="yes" checked>
    Cash
    <input name="pay_others" type="checkbox" id="pay_others" value="yes"> 
                Others</span></td>
            </tr>
            <tr>
                <td><span class="style31">Programme Category:</span>
                </td>
                <td><select name="progCat" id="progCat"><?php echo "$catoption_block"?>
                    </select> <span class="style13">*</span> 
                </td>
            </tr>
            <tr>
                <td><span class="style31">Training Level:</span>
                </td>
                <td><select name="trglvl" id="trglvl"><?php echo "$trglvloption_block"?>
                    </select><span class="style13">*</span>
                </td>
            </tr>
            <tr>
                <td><span class="style31">Collaborating partner:</span>
                </td>
                   <td><select name="collabPartner" id="collabPartner"><?php echo "$collaboption_block"?>
                    </select>
                </td>
            </tr>
            <tr>
                <td><span class="style31">Maximum Participants:</span>
                </td> 
                <td><input name="maxParticipants" type="text" id="maxParticipants" size="10" maxlength="10">
                </td>
            </tr>   
             <tr>
                <td><span class="style31">Minimum Participants:</span>
                </td>
                <td><input name="minParticipants" type="text" id="minParticipants" size="10" maxlength="10">
                </td>
            </tr>
            <tr>
                <td><span class="style31">Certificate:</span>
                </td>
                <td><select name="cert" id="cert"><?php echo "$certoption_block"?>
                    </select>
                </td>
            </tr>
            <tr>
                <td><span class="style31">Remarks:</span>
                </td>
                <td><textarea name="remarks" cols="50" rows="4" id="remarks" type="text"></textarea>
                </td>
            </tr>
            <tr>
                <td><span class="style31">Status:</span>
                </td>
                <td><select name="status" id="status"><?php echo "$statusoption_block"?>
                    </select>
                </td>
            </tr>
            <tr>
            
                <td>&nbsp;
                </td>
            </tr>
            <tr>
                <td>
              <td><input type="submit" name="Submit" value="Submit">
              </td>
            </tr>
               <tr>
                <td class="style25"><span class="style27">*</span>- mandatory 
                </td>
            </tr>
        </table>
        <br><br>
    <?php
    }
    ?>
    </form>

    <SCRIPT language="JavaScript">
        var frmvalidator  = new Validator("eventreg");
        frmvalidator.addValidation("clientName","req", "Please choose a client.");
        frmvalidator.addValidation("mainTitle","req", "Please enter your main title.");
        frmvalidator.addValidation("startDate","req", "Please enter a starting date.");
        frmvalidator.addValidation("venue", "dontselect=0", "Please select a venue.");
        frmvalidator.addValidation("trglvl", "dontselect=0", "Please select a training level.");
    </script>

    </body>
    </html>
    PHP Code:
    //simple upload script
    <?php
    //Mmaximum file size. You may increase or decrease.
    $MAX_SIZE 5000000;
                                
    //Allowable file ext. names. you may add more extension names.            
    $FILE_EXTS  = array('.zip','.jpg','.png','.gif','.doc','.pdf'); 

    //Allow file delete? no, if only allow upload only
    $DELETABLE  false;                               


    //vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv
    //   Do not touch the below if you are not confident.
    //^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    /************************************************************
     *     Setup variables
     ************************************************************/
    $site_name $_SERVER['HTTP_HOST'];
    $url_dir "http://".$_SERVER['HTTP_HOST'].dirname($_SERVER['PHP_SELF']);
    $url_this =  "http://".$_SERVER['HTTP_HOST'].$_SERVER['PHP_SELF'];

    $upload_dir "files/";
    $upload_url $url_dir."/files/";
    $message ="";

    /************************************************************
     *     Create Upload Directory
     ************************************************************/
    if (!is_dir("files")) {
      if (!
    mkdir($upload_dir))
          die (
    "upload_files directory doesn't exist and creation failed");
      if (!
    chmod($upload_dir,0755))
          die (
    "change permission to 755 failed.");
    }

    /************************************************************
     *     Process User's Request
     ************************************************************/
    if ($_REQUEST[del] && $DELETABLE)  {
      
    $resource fopen("log.txt","a");
      
    fwrite($resource,date("Ymd h:i:s")."DELETE - $_SERVER[REMOTE_ADDR]"."$_REQUEST[del]\n");
      
    fclose($resource);
      
      if (
    strpos($_REQUEST[del],"/.")>0);                  //possible hacking
      
    else if (strpos($_REQUEST[del],$upload_dir) === false); //possible hacking
      
    else if (substr($_REQUEST[del],0,6)==$upload_dir) {
        
    unlink($_REQUEST[del]);
        print 
    "<script>window.location.href='$url_this?message=deleted successfully'</script>";
      }
    }
    else if (
    $_FILES['userfile']) {
      
    $resource fopen("log.txt","a");
      
    fwrite($resource,date("Ymd h:i:s")."UPLOAD - $_SERVER[REMOTE_ADDR]"
                
    .$_FILES['userfile']['name']." "
                
    .$_FILES['userfile']['type']."\n");
      
    fclose($resource);

      
    $file_type $_FILES['userfile']['type']; 
      
    $file_name $_FILES['userfile']['name'];
      
    $file_ext strtolower(substr($file_name,strrpos($file_name,".")));

      
    //File Size Check
      
    if ( $_FILES['userfile']['size'] > $MAX_SIZE
         
    $message "The file size is over 2MB.";
      
    //File Extension Check
      
    else if (!in_array($file_ext$FILE_EXTS))
         
    $message "Sorry, $file_name($file_type) is not allowed to be uploaded.";
      else
         
    $message do_upload($upload_dir$upload_url);
      
      print 
    "<script>window.location.href='$url_this?message=$message'</script>";
    }
    else if (!
    $_FILES['userfile']);
    else 
        
    $message "Invalid File Specified.";

    /************************************************************
     *     List Files
     ************************************************************/
    $handle=opendir($upload_dir);
    $filelist "";
    while (
    $file readdir($handle)) {
       if(!
    is_dir($file) && !is_link($file)) {
          
    $filelist .= "<a href='$upload_dir$file'>".$file."</a>";
          if (
    $DELETABLE)
            
    $filelist .= " <a href='?del=$upload_dir".urlencode($file)."' title='delete'>x</a>";
          
    $filelist .= "<sub><small><small><font color=grey>  ".date("d-m H:i"filemtime($upload_dir.$file))
                       .
    "</font></small></small></sub>";
          
    $filelist .="<br>";
       }
    }

    function 
    do_upload($upload_dir$upload_url) {

        
    $temp_name $_FILES['userfile']['tmp_name'];
        
    $file_name $_FILES['userfile']['name']; 
      
    $file_name str_replace("\\","",$file_name);
      
    $file_name str_replace("'","",$file_name);
        
    $file_path $upload_dir.$file_name;

        
    //File Name Check
      
    if ( $file_name =="") { 
          
    $message "Invalid File Name Specified";
          return 
    $message;
      }

      
    $result  =  move_uploaded_file($temp_name$file_path);
      if (!
    chmod($file_path,0777))
           
    $message "change permission to 777 failed.";
      else
        
    $message = ($result)?"$file_name uploaded successfully." :
                   
    "Somthing is wrong with uploading a file.";
      return 
    $message;
    }

    ?>

    <center>
       <font color=red><?=$_REQUEST[message]?></font>
       <br>
       <form name="upload" id="upload" ENCTYPE="multipart/form-data" method="post">
         <font size="1" face="Tahoma, sans-serif">Event Brochure:</font>     
         <input type="file" id="userfile" name="userfile">
         <input type="submit" name="upload" value="Upload">
       </form>
       
       <br><b>My Files</b>
       <hr width=70%>
       <?=$filelist?>
       <hr width=70%>
       <small><sup>Developed By 
       <a style="text-decoration:none" href="http://tech.tailoredweb.com">TailoredWeb.com</a>
       </sup></small>
    </center>
    if the simple upload file can be incorporated into the form, how should i then display the file that is being uploaded in the next page?

    i have pages that allows the details to be edited. so the upload should still function there.
    [=cHeRyL=]

  • #2
    Regular Coder
    Join Date
    Aug 2005
    Posts
    145
    Thanks
    0
    Thanked 0 Times in 0 Posts
    you want to upload ..something like :

    PHP Code:

    <?php  






    if(!($_FILES["userfile"]["name"]=="")) 
    {
        
    $uploaddir="./your directory/";
        
    //copy the file to some permanent location 
        
        
    if (move_uploaded_file($_FILES["userfile"]["tmp_name"], $uploaddir.$_FILES["userfile"]["name"])) 
        {
        echo(
    "<p>File uploaded<p><p>");
        } 
        else 
        {
        echo (
    "<p>Error in uploading file to m-v! Please try again.<br>");
        if(
    $_FILES['userfile']['error']==1) echo "<font color=red>Error: File size exceeds maximum permissible limit of 2MB</font><p><p>";
        }


    ?>


  •  

    Posting Permissions

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