php - My uploader doesnt seem to work (CodeIgniter) -
i trying use uploader called max file upload. controller calls view called upload_view.php. here codes it: [both these codes placed in application/views folder]
upload_view.php
<?php require_once("maxupload.class.php"); ?> <!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=utf-8" /> <title>max's file uploader</title> <link href="style/style.css" rel="stylesheet" type="text/css" /> </head> <body> <?php $myupload = new maxupload(); //$myupload->setuploadlocation(getcwd().directory_separator); $myupload->uploadfile(); ?> </body>
and here maxupload.class.php
<?php /************************************************* * max's file uploader * * version: 1.0 * date: 2007-11-26 * ****************************************************/ class maxupload{ var $uploadlocation; /** * constructor initialize class varaibles * uploadlocation set actual * working directory * * @return maxupload */ function maxupload(){ $this->uploadlocation = getcwd().directory_separator; } /** * function sets directory upload file * in case of windows server use form: c:\\temp\\ * in case of unix server use form: /tmp/ * * @param string directory store files */ function setuploadlocation($dir){ $this->uploadlocation = $dir; } function showuploadform($msg='',$error=''){ ?> <div id="container"> <div id="header"><div id="header_left"></div> <div id="header_main">max's file uploader</div><div id="header_right"></div></div> <div id="content"> <?php if ($msg != ''){ echo '<p class="msg">'.$msg.'</p>'; } else if ($error != ''){ echo '<p class="emsg">'.$error.'</p>'; } ?> <form action="" method="post" enctype="multipart/form-data" > <center> <label>file: <input name="myfile" type="file" size="30" /> </label> <label> <input type="submit" name="submitbtn" class="sbtn" value="upload" /> </label> </center> </form> </div> <div id="footer"><a href="http://www.phpf1.com" target="_blank">powered php f1</a></div> </div> <?php } function uploadfile(){ if (!isset($_post['submitbtn'])){ $this->showuploadform(); } else { $msg = ''; $error = ''; //check destination directory if (!file_exists($this->uploadlocation)){ $error = "the target directory doesn't exists!"; } else if (!is_writeable($this->uploadlocation)) { $error = "the target directory not writeable!"; } else { $target_path = $this->uploadlocation . basename( $_files['myfile']['name']); if(@move_uploaded_file($_files['myfile']['tmp_name'], $target_path)) { $msg = basename( $_files['myfile']['name']). " uploaded successfully!"; } else{ $error = "the upload process failed!"; } } $this->showuploadform($msg,$error); } } } ?>
whenever add
$query = $this->db->get('filename'); $folder_name = underscore($query->row()->file_name);
inside function maxuplod() in maxupload.class.php file, upload page doesnt show up. use $folder_name later add download dir, custom folders can created.
when code placed within maxupload.class.php, doesnt load anything. error log shows error @ same line db accessed. without files can uploaded static upload folder.
any ideas on why happening?
thanks lot help.
Comments
Post a Comment