how to assign file while editting record with other fields

Last post 12-23-2010, 1:04 AM by jaydev. 2 replies.
Sort Posts: Previous Next
  •  12-22-2010, 12:07 AM 65494

    how to assign file while editting record with other fields


    I am using file uploader with other fields.
    Here is my code for uploader.
                       $uploader=new PhpUploader();
                        $uploader->Name="ufile1";
                        $uploader->MaxSizeKB=102400;  
                        $uploader->AllowedFileExtensions="*.mp3,*.mp4,*.wma";    
                        $uploader->ManualStartUpload=true;
                        $uploader->ShowProgressInfo=false;   
                        $uploader->FlashUploadMode="Http";
                        $uploader->Render(); 
     
    function doStart()
        {
            if(document.getElementById('ufile1'))
            {
                var uploadobj = document.getElementById('ufile1');
                if (uploadobj.getqueuecount() > 0)
                {
                    uploadobj.startupload();
                }else
                    {
                        alert("Please browse file for upload");
                    }
            }
            
            if(document.getElementById('newimage'))
            {
                var uploadobj2 = document.getElementById('newimage');
                if (uploadobj2.getqueuecount() > 0)
                {
                    uploadobj2.startupload();
                }else
                    {
                        alert("Please browse image file for upload");
                    }
            }        
        }
     
    function validate()
    {

        if(document.frmaddfiles.name1.value=='')
          {
               alert("Please Enter Filename.");
               document.frmaddfiles.name1.focus();
               return false;
          }

        
        if(document.frmaddfiles.descr.value.length < 1)
          {
               alert("Please Enter Description.");
               document.frmaddfiles.descr.focus();
               return false;
          }       
        if(document.frmaddfiles.rdate.value.length < 1)
          {
               alert("Please Select Release Date.");
               document.frmaddfiles.rdate.focus();
               return false;
          }
        

        if(document.frmaddfiles.active.value=='')
          {
               alert("Please Select Status.");
               document.frmaddfiles.active.focus();
               return false;
          }
          return true;
    }
     
    <form name="frmaddfiles" action="sub_files.php" method="post" onSubmit="return validate();" target="_parent" enctype="multipart/form-data">
     
     
    Now, when i submit this form, it calls 'doStart()' method .And I have to write 'return false' here.
    <input name="Submit" type="submit"  value="SUBMIT" onClick="doStart();return false;">
    and onsubmit  it calls validation method for other records in form.
     
    While Adding it works fine. but when I edit just name in this form. (Please see the image below.its second file uploader.if i delete it shows me button for browse) it doesnt allow me to submit the form.
     

                  
     
     
     
    Waiting for replay.
    .
     
  •  12-22-2010, 3:59 PM 65504 in reply to 65494

    Re: how to assign file while editting record with other fields

    Dear jaydev,
     
    Please refer to the following code:
     
    <?php require_once "phpuploader/include_phpuploader.php" ?>
    <?php session_start(); ?>
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
     <title>
      Form - Start uploading manually
     </title>   
     <script type="text/javascript">
     function doStart()
     {
      if(document.getElementById('ufile1'))
            {
                var uploadobj = document.getElementById('ufile1');
                if (uploadobj.getqueuecount() > 0)
                {
                    uploadobj.startupload();
                }else
                    {
                        alert("Please browse file for upload");
                    }
            }
           
            if(document.getElementById('newimage'))
            {
                var uploadobj2 = document.getElementById('newimage');
                if (uploadobj2.getqueuecount() > 0)
                {
                    uploadobj2.startupload();
                }else
                    {
                        alert("Please browse image file for upload");
                    }
            }
     }
     </script>
     
    </head>
    <body>
     <div class="demo">    
       <h2>Start uploading manually</h2>
       <p>This sample demonstrates how to start uploading manually after file selection vs automatically.</p>
       <P>Allowed file types: <span style="color:red">jpg, gif, txt, png, zip</span></p>

       <!-- do not need enctype="multipart/form-data" -->
       <form id="form1" method="POST">
        <?php    
         $uploader=new PhpUploader();
         $uploader->MaxSizeKB=10240;
         $uploader->Name="ufile1";
         $uploader->InsertText="Select multiple files (Max 1M)";
         $uploader->AllowedFileExtensions="*.jpg,*.png,*.gif,*.txt,*.zip,*.rar"; 
         $uploader->MultipleFilesUpload=true;
         $uploader->ManualStartUpload=true;
         $uploader->Render();
         
         $uploader=new PhpUploader();
         $uploader->MaxSizeKB=10240;
         $uploader->Name="newimage";
         $uploader->InsertText="Select multiple files (Max 10M)";
         $uploader->AllowedFileExtensions="*.jpg,*.png,*.gif,*.txt,*.zip,*.rar"; 
         $uploader->MultipleFilesUpload=true;
         $uploader->ManualStartUpload=true;
         $uploader->Render();
        ?>
        <br /><br /><br />
        <button id="submitbutton" onclick="doStart();return false;">Start Uploading Files</button>

       </form>
       
       <br/><br/><br/>
    <?php
    $fileguidlist=@$_POST["ufile1"];
    if($fileguidlist)
    {
     $guidlist=explode("/",$fileguidlist);
     
     echo("<div style='font-family:Fixedsys;'>");
     echo("Uploaded ");
     echo(count($guidlist));
     echo(" files:");
     echo("</div>");
     echo("<hr/>");
     
     foreach($guidlist as $fileguid)
     {
      $mvcfile=$uploader->GetUploadedFile($fileguid);
      if($mvcfile)
      {
       echo("<div style='font-family:Fixedsys;border-bottom:dashed 1px gray;padding:6px;'>");
       echo("FileName: ");
       echo($mvcfile->FileName);
       echo("<br/>FileSize: ");
       echo($mvcfile->FileSize." b");
     //  echo("<br/>FilePath: ");
     //  echo($mvcfile->FilePath);
       echo("</div>");
       
       //Moves the uploaded file to a new location.
       $mvcfile->MoveTo("c:/temp");
       //Copys the uploaded file to a new location.
       //$mvcfile->CopyTo("/uploads");
       //Deletes this instance.
       //$mvcfile->Delete();
      }
     }
    }
    $fileguidlist2=@$_POST["newimage"];
    if($fileguidlist2)
    {
     $guidlist2=explode("/",$fileguidlist2);
     
     echo("<div style='font-family:Fixedsys;'>");
     echo("Uploaded ");
     echo(count($guidlist2));
     echo(" files:");
     echo("</div>");
     echo("<hr/>"); 
     foreach($guidlist2 as $fileguid)
     {
      $mvcfile=$uploader->GetUploadedFile($fileguid);
      if($mvcfile)
      {
       echo("<div style='font-family:Fixedsys;border-bottom:dashed 1px gray;padding:6px;'>");
       echo("FileName: ");
       echo($mvcfile->FileName);
       echo("<br/>FileSize: ");
       echo($mvcfile->FileSize." b");
     //  echo("<br/>FilePath: ");
     //  echo($mvcfile->FilePath);
       echo("</div>");   
       //Moves the uploaded file to a new location.
       $mvcfile->MoveTo("c:/temp");
       //Copys the uploaded file to a new location.
       //$mvcfile->CopyTo("/uploads");
       //Deletes this instance.
       //$mvcfile->Delete();
      }
     }
    }
    ?>    
     </div>
    </body>
    </html>
     
    Thank you for asking
  •  12-23-2010, 1:04 AM 65508 in reply to 65504

    Re: how to assign file while editting record with other fields

    Dear Eric,
     
    My Add / Edit  code is on the same page.
    I am using "function validation()" on submit the form for other function.

    <form name="frmaddfiles" action="sub_files.php" method="post" onSubmit="return validate();" target="_parent" enctype="multipart/form-data">
    and on button 
     
    <input name="Submit" type="submit"  value="SUBMIT" onClick="doStart();return false;">
    </form>
     
    so while editing if  I found the file on my record i do not use uploader. And if uploader is not present in the form doStart method does not allow me to submit the form.
     
View as RSS news feed in XML