<?php class start extends Controller { function start() { parent::Controller(); $this->load->helper(array('form', 'url', 'file')); } function index() { $this->load->view('show', array('error' => ' ' )); } function do_upload() { $config['file_name']= 'keeppic'; // ตรงนี้ผมกระจะสุ่มโดยใช้ฟังก์ชัน random $config['upload_path'] = 'D:/AppServ/www/code/system/application/uploads/'; // ตำแหน่งอัพโหลด $config['allowed_types'] = 'jpeg|jpg|gif|png'; $config['max_size'] = '1024'; $this->load->library('upload', $config); $field_name = "file"; if ( ! $this->upload->do_upload($field_name)) { $error = array('error' => $this->upload->display_errors()); $this->load->view('show', $error); } else { echo "upload ok"; } } } ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> <title>Untitled Document</title> </head> <body> <?php echo form_open_multipart('start/do_upload');?> File:<br /> <input name="file" type="file" /><br /> <input type="submit" name="submit" value="Upload" /> <?php echo form_close(); ?> </body> </html>
dirname(BASEPATH)."/"; //<--ตรงนี้จะได้ path ไปยังตำแหน่ง web root จากนั้นคุณก็เติมเอาว่าจาก root จะไว้ตรง folder ไหนต่อ
Quote:file_name None Desired file name If set CodeIgniter will rename the uploaded file to this name. The extension provided in the file name must also be an allowed file type.
เพื่อความปลอดภัยของเว็บบอร์ด ไม่อนุญาติให้แทรก แท็ก [img]....[/img] โดยการอัพโหลดไฟล์รูปจากที่อื่น เช่นเว็บไซต์ ฟรีอัพโหลดต่าง ๆ อัพโหลดแทรกรูปภาพ ให้ใช้บริการอัพโหลดไฟล์ของไทยครีเอท และตัดรูปภาพให้พอดีกับสกรีน เพื่อความโหลดเร็วและไฟล์ไม่ถูกลบทิ้ง