Rifky Apriadi

July 16, 2008

how to upload word(doc) with PHP

Filed under: PHP

post sebelumnya udah bisa upload file, tapi itu cuma bisa upload image aja! gimana kalau ada file doc yang mau d upload? tanya lagi sama paman google, an paman google yg baik hati mengantarkan aku sehingga dapat source ini :

<?php
      if(isset($_POST[’submit’])){
      $numfilesuploaded = $_POST[’numuploads’];
      $count = 1;
 
          while ($count <= $numfilesuploaded)
          {
                  $conname = “new_file”.$count;

                  $filetype = $_FILES[$conname][’type’];
                
                  $filename = $_FILES[$conname][’name’];
                  if ($filename != ‘’)
                  {
                    if ($filetype == “application/msword” || $filetype==”application/vnd.openxmlformats-officedocument.wordprocessingml.document”)
                    {
                        $maxfilesize = $_POST[’maxsize’];
                        $filesize = $_FILES[$conname][’size’];
                        if($filesize <= $maxfilesize )
                        {
                              $randomdigit = rand(0000,9999);
                            
                              $newfilename = $randomdigit.$filename;
                              $source = $_FILES[$conname][’tmp_name’];
                              $target = “document/”.$newfilename;
                              move_uploaded_file($source, $target);
                              echo $count.” File uploaded | “;
                     
                       
                        }
                        else
                        {
                            echo $count.” File is too big! 10MB limit! |”;
                       
                        }
                    }
                    else
                    {
                        echo ” The file is not a supported type |”;
      echo $filetype;
                    }
                  }
          $count = $count + 1;
          }
     
      }
?>
<?php
    $numuploads = 1;
    $count = 1;
?>
<form action=”<?php echo $_server[’php-self’];  ?>” method=”post” enctype=”multipart/form-data” id=”something” class=”uniForm”>
<?php
      while ($count <= $numuploads)
      {

?>
      <input name=”new_file<?php echo $count; ?>” id=”new_file<?php echo $count; ?>” size=”30″ type=”file” class=”fileUpload” />
      <?php
            $count = $count + 1;
      }
?>
      <input type = “hidden” name=”maxsize” value = “10240000″>
       <input type = “hidden” name=”numuploads” value = “<?php echo $numuploads; ?>”>
      <br>
      <button name=”submit” type=”submit” class=”submitButton”>Upload Files</button>

</form>

ya, mudah-mudahan bisa bermanfaat untuk yang membutuhkannya!

Comments »

No comments yet.

RSS feed for comments on this post.

Leave a comment

Line and paragraph breaks automatic, e-mail address never displayed, HTML allowed: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <code> <em> <i> <strike> <strong>



Anti-spam measure: please retype the above text into the box provided.

Get free blog up and running in minutes with Blogsome
Theme designed by Ian Main