<!DOCTYPE html> <html> <head> <meta charset="utf-8" /> <title>test vfileup</title> </head> <body> <div style="border: 1px solid #eee; margin: 150px auto 0 auto; overflow: hidden; padding: 10px; width: 500px;"> <h1 style="font-size: 20px;">vfileup : PHP vee's file upload class.</h1> <?php if ( isset($form_status) ) {echo $form_status;} ?> <form method="post" action="sample.php" enctype="multipart/form-data"> <input type="hidden" name="MAX_FILE_SIZE" value="2097152" /><!--2097152 byte = 2MB --> file: <input type="file" name="file" value="" /><br /> <button type="submit" name="btn">Upload</button> </form> <span style="color:#aaa; font-size: 11px;">© <a href="http://rundiz.com" style="color:#aaa;">rundiz.com</a></span> </div> </body> </html>
<?php if ( isset($_FILES['file']['name']) && $_FILES['file']['name'] != null ) { include(dirname(__FILE__)."/vfileup.php"); $vfileup = new vfileup($_FILES['file']); // config upload $vfileup->allowed_types = "jpg|gif|png|txt"; $vfileup->encrypt_name = true; $vfileup->filename = '';// กำหนดชื่อเฉยๆ ไม่ต้องมี .ext $vfileup->max_size = "";// size in byte $vfileup->overwrite = false; $vfileup->remove_space = true; $vfileup->upload_path = dirname(__FILE__); // upload $upload_result = $vfileup->do_upload(); if ( $upload_result !== true ) { $form_status = "<div class=\"block-error\">" . $vfileup->error_msg . "</div>"; } else { $form_status = "<div class=\"block-success\">success</div>"; $data = $vfileup->data(); echo "ชื่อไฟล์ที่อัพโหลดสำเร็จแล้วคือ " . $data['file_name'] . " มีขนาด " . $data['file_size'] . " bytes, ประเภทไฟล์ " . $data['file_type']; } } ?>