CFile.php 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. <?php
  2. /**
  3. * FecShop file.
  4. *
  5. * @link http://www.fecshop.com/
  6. * @copyright Copyright (c) 2016 FecShop Software LLC
  7. * @license http://www.fecshop.com/license/
  8. */
  9. namespace fec\helpers;
  10. use Yii;
  11. /**
  12. * @author Terry Zhao <2358269014@qq.com>
  13. * @since 1.0
  14. */
  15. class CFile
  16. {
  17. # 1.保存前台上传的文件。
  18. public static function saveUploadFile($fileFullDir,$fileType = ''){
  19. if($fileType){
  20. $name = $_FILES["file"]["name"];
  21. if(strstr($name,$fileType)){
  22. $result = @move_uploaded_file($_FILES["file"]["tmp_name"],$fileFullDir);
  23. }
  24. }else{
  25. $result = @move_uploaded_file($_FILES["file"]["tmp_name"],$fileFullDir);
  26. }
  27. return $result;
  28. }
  29. # 2.得到csv文件的内容,返回数组
  30. public static function getCsvFileContent($fileDir){
  31. $fp = @fopen($fileDir, "r");
  32. $content = [];
  33. if($fp){
  34. while(! @feof($fp))
  35. {
  36. $c = @fgets($fp);
  37. //$c = str_replace("\"","",$c);
  38. //$c = str_replace("'","",$c);
  39. $c_arr = explode(",",$c);
  40. $arr = [];
  41. foreach($c_arr as $v){
  42. $arr[] = trim($v);
  43. }
  44. $content[] = $arr;
  45. }
  46. fclose($fp);
  47. }
  48. return $content;
  49. }
  50. }