Advertisement
Guest User

peetlnwza

a guest
Apr 10th, 2016
103
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 9.64 KB | None | 0 0
  1. <?php
  2.  
  3. $ftp_server = "localhost";
  4. $ftp_user_name = "กูไม่บอกรหัส";
  5. $ftp_user_pass = "กูไม่บอก";
  6. $port = "2002" ;
  7.  
  8.  
  9. $destination_file = $_FILES['file']['name'];
  10. $source_file = $_FILES['file']['tmp_name'];
  11. $size_file = $_FILES['file']['size'];
  12.  
  13.  
  14. if ($destination_file == "") {
  15.     header("Location:add_student.php");
  16.     exit;
  17. }
  18. if (strtoupper(substr($destination_file, -4)) != '.CSV' ) {
  19.     header("Location:add_student.php");
  20.     exit;
  21. }
  22.  
  23. // set up basic connection
  24. $conn_id = ftp_connect($ftp_server, $port);
  25.  
  26. // login with username and password
  27. $login_result = ftp_login($conn_id, $ftp_user_name, $ftp_user_pass);
  28.  
  29. ftp_chdir($conn_id, "CSV Files");
  30.  
  31. // check connection  
  32.  
  33. if ((!$conn_id) || (!$login_result)) {
  34.     echo "FTP connection has failed!";
  35.     echo "Attempted to connect to $ftp_server for user $ftp_user_name";
  36.     exit;
  37. } else {
  38. //    echo "Connected to $ftp_server, for user $ftp_user_name<br/>";
  39. }
  40.  
  41. // upload the file  
  42. $upload = ftp_put($conn_id, 'student.csv', $source_file, FTP_BINARY);
  43.  
  44. // check upload status  
  45. if (!$upload) {
  46.     echo "FTP upload has failed!";
  47. }
  48.  
  49. // close the FTP stream  
  50. ftp_close($conn_id);
  51. ?>
  52. <!DOCTYPE html>
  53. <!--[if IE 8]> <html lang="en" class="ie8"> <![endif]-->
  54. <!--[if IE 9]> <html lang="en" class="ie9"> <![endif]-->
  55. <!--[if IE 10]> <html lang="en" class="ie10"> <![endif]-->
  56. <!--[if !IE]><!--> <html lang="en"> <!--<![endif]-->
  57. <!-- BEGIN HEAD -->
  58.  
  59. <?php
  60.     /*
  61.     session_start();
  62.     if ($_SESSION['sess_userid'] == "") {
  63.         header("Location: ../../staffLogin.php");
  64.         die();
  65.     }
  66.  
  67.     if ($_SESSION['sess_position'] != "general") {
  68.         header("Location: ../../staffLogin.php");
  69.         die();
  70.     }
  71. */
  72.     include '../../../connection.php';
  73. //    $strSQL = "SELECT * FROM staff_login WHERE username = '" . $_SESSION['sess_userid'] . "' ";
  74.     mysql_query("SET NAMES UTF8");
  75. //    $objQuery = mysql_query($strSQL);
  76. //   $objResult = mysql_fetch_array($objQuery);
  77.     $today = getdate();
  78.     $nowyear = $today['year'] + 543;
  79.     ?>
  80.     <head>
  81.       <meta charset="utf-8">
  82.       <meta http-equiv="X-UA-Compatible" content="IE=edge">
  83.       <title>Dormitory Management System</title>
  84.       <!-- Tell the browser to be responsive to screen width -->
  85.       <meta content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no" name="viewport">
  86.       <!-- Bootstrap 3.3.6 -->
  87.       <link rel="stylesheet" href="../../bootstrap/css/bootstrap.min.css">
  88.       <!-- Font Awesome -->
  89.       <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.5.0/css/font-awesome.min.css">
  90.       <!-- Ionicons -->
  91.       <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/ionicons/2.0.1/css/ionicons.min.css">
  92.       <!-- Theme style -->
  93.       <link rel="stylesheet" href="../../dist/css/AdminLTE.min.css">
  94.   <!-- AdminLTE Skins. Choose a skin from the css/skins
  95.   folder instead of downloading all of them to reduce the load. -->
  96.   <link rel="stylesheet" href="../../dist/css/skins/_all-skins.min.css">
  97.   <!-- bootstrap wysihtml5 - text editor -->
  98.   <link rel="stylesheet" href="../../plugins/bootstrap-wysihtml5/bootstrap3-wysihtml5.min.css">
  99.  
  100.   <!-- HTML5 Shim and Respond.js IE8 support of HTML5 elements and media queries -->
  101.   <!-- WARNING: Respond.js doesn't work if you view the page via file:// -->
  102.   <!--[if lt IE 9]>
  103.   <script src="https://oss.maxcdn.com/html5shiv/3.7.3/html5shiv.min.js"></script>
  104.   <script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script>
  105.   <![endif]-->
  106. </head>
  107. <!-- END HEAD -->
  108. <!-- BEGIN BODY -->
  109. <body class="fixed-top">
  110.     <?php //include 'stafftag.php' ?>
  111.     <div class="container-fluid">
  112.         <!-- BEGIN PAGE HEADER-->  
  113.         <div class="row-fluid">
  114.             <div class="span12">
  115.  
  116.                 <!-- BEGIN PAGE TITLE & BREADCRUMB-->
  117.                 <h3 class="page-title">
  118.                     เพิ่มรายชื่อนักศึกษา
  119.                 </h3>
  120.                 <ul class="breadcrumb">
  121.                     <li>
  122.                         <i class="icon-home"></i>
  123.                         <a href="index.php">หน้าแรก</a> <span class="divider">/</span>
  124.                     </li>
  125.                     <li class="active">เพิ่มรายชื่อนักศึกษา</li>
  126.                 </ul>
  127.                 <!-- END PAGE TITLE & BREADCRUMB-->
  128.             </div>
  129.         </div>
  130.         <!-- END PAGE HEADER-->
  131.  
  132.  
  133.  
  134.         <div class="widget-body form">
  135.           <!-- BEGIN FORM-->
  136.           <form class="form-horizontal has-validation-callback" method="post" action="StudentAddtoMySQL.php">
  137.             <!--student data-->
  138.             <div class="panel panel-default">
  139.               <div class="panel-body">                                            
  140.                 <legend>รายชื่อนักศึกษา</legend>
  141.                 <!--line1-->
  142.                 <div class="form-group">
  143.                   <div class="widget-body form">
  144.                     <!-- BEGIN FORM-->
  145.                     <div class="box-body">
  146.                         <h4> ปีการศึกษา <?php echo $_POST['txtyear']; ?> </h4>
  147.                         <table class="table  table-bordered" id="sample_1">
  148.                             <thead>
  149.                                 <tr class="btn-info">
  150.                                     <th>ลำดับ</th>
  151.                                     <th>โครงการที่รับสมัคร</th>
  152.                                     <th>สาขาวิชาที่สมัคร</th>
  153.                                     <th>หมายเลขบัตรประชาชน</th>
  154.                                     <th>ชื่อ</th>
  155.                                     <th>นามสกุล</th>
  156.                                     <th>เพศ</th>
  157.                                     <th>หมายเลขโทรศัพท์</th>
  158.                                 </tr>
  159.                             </thead>
  160.                             <tbody>
  161.                                 <?php
  162.                                 $row = 0;
  163.                                 $fp = @ fopen("../../files/CSV Files/student.csv", "r");
  164.                                 if (!$fp) {
  165.                                     echo "ไม่สามารถเปิดไฟล์ได้ โปรดลองอีกครั้งในภายหลัง";
  166.                                     exit;
  167.                                 }
  168.                                 while (($data = fgetcsv($fp, 3000, ",")) !== FALSE) {
  169.                                     $num = count($data);
  170.                                     if ($row == 0) {
  171.                                         $row++;
  172.                                     } else { ?>
  173.                                         <tr>
  174.                                         <td>
  175.                                             <?php
  176.                                             echo $row;
  177.                                             $row++;
  178.                                             ?>
  179.                                         </td>
  180.                                             <td><?php echo $data[0]; ?></td>
  181.                                             <td><?php echo $data[1]; ?></td>
  182.                                             <td><?php echo $data[2]; ?></td>
  183.                                             <td><?php echo $data[3]; ?></td>
  184.                                             <td><?php echo $data[4]; ?></td>
  185.                                             <td><?php echo $data[5]; ?></td>
  186.                                             <td><?php echo $data[6]; ?></td>
  187.                                         </tr>
  188.                                         <?php
  189.                                     }
  190.                                 }
  191.  
  192.                                 fclose($fp);
  193.                                
  194.                                 ?>
  195.                             </tbody>
  196.                         </table>
  197.                     </div>
  198.                     <!-- END FORM-->        
  199.                 </div>
  200.             </div>
  201.  
  202.             <hr>
  203.  
  204.             <div id="success"></div>
  205.             <!-- For success/fail messages -->
  206.  
  207.             <div align="right">
  208.                 <button class="btn btn-danger" data-dismiss="fileupload" onclick="history.back();">ยกเลิก</button>
  209.                 <button type="submit" class="btn btn-info" name="file" value="studentlist.csv">เพิ่มรายชื่อลงฐานข้อมูล</button>
  210.             </div>
  211.         </form>
  212.     </div>
  213. </div>
  214. </div>
  215.  
  216. </div>
  217. <?php
  218. // include 'stafftag2.php'
  219. ?>
  220. <!-- jQuery 2.2.0 -->
  221. <script src="../../plugins/jQuery/jQuery-2.2.0.min.js"></script>
  222. <!-- Bootstrap 3.3.6 -->
  223. <script src="../../bootstrap/js/bootstrap.min.js"></script>
  224. <!-- FastClick -->
  225. <script src="../../plugins/fastclick/fastclick.js"></script>
  226. <!-- AdminLTE App -->
  227. <script src="../../dist/js/app.min.js"></script>
  228. <!-- AdminLTE for demo purposes -->
  229. <script src="../../dist/js/demo.js"></script>
  230. <!-- CK Editor -->
  231. <script src="https://cdn.ckeditor.com/4.5.7/standard/ckeditor.js"></script>
  232. <!-- Bootstrap WYSIHTML5 -->
  233. <script src="../../plugins/bootstrap-wysihtml5/bootstrap3-wysihtml5.all.min.js"></script>
  234. <script>
  235. $(function () {
  236.     // Replace the <textarea id="editor1"> with a CKEditor
  237.     // instance, using default configuration.
  238.     CKEDITOR.replace('editor1');
  239.     //bootstrap WYSIHTML5 - text editor
  240.     $(".textarea").wysihtml5();
  241. });
  242. </script>
  243. </body>
  244. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement