×ðÁú¿­Ê±

thinkphpÔõôÉÏ´«txtµ½Êý¾Ý¿â

thinkphpÊÇÒ»¿îÓÅÒìµÄphp¿ª·¢¿ò¼Ü£¬¸Ã¿ò¼ÜÌṩÁËÐí¶à±ã½ÝµÄ¹¦Ð§£¬°üÀ¨ÎļþÉÏ´«¡£ÔÚ±¾ÎÄÖУ¬ÎÒÃǽ«ÌÖÂÛÔõÑùʹÓÃthinkphp½«txtÎļþÉÏ´«µ½Êý¾Ý¿â¡£

½¨ÉèÊý¾Ý¿â±í

Ê×ÏÈ£¬ÎÒÃÇÐèÒª½¨ÉèÒ»¸öÊý¾Ý¿â±íÀ´´æ´¢ÉÏ´«µÄtxtÎļþ¡£ÔÚ±¾ÀýÖУ¬ÎÒÃǽ«½¨ÉèÒ»¸öÃûΪ¡°txt_data¡±µÄ±í£¬¸Ã±í°üÀ¨Á½¸ö×ֶΣº¡°id¡±ºÍ¡°content¡±¡£ÆäÖУ¬¡°id¡±ÊÇÖ÷¼ü£¬×Ô¶¯µÝÔö£¬¶ø¡°content¡±ÊÇÓÃÓÚ´æ´¢txtÎļþÄÚÈݵÄ×ֶΡ£

½¨ÉèÉÏ´«±íµ¥

½ÓÏÂÀ´£¬ÎÒÃǽ«½¨ÉèÒ»¸öÉÏ´«±íµ¥£¬ÒÔ±ãÓû§¿ÉÒÔÑ¡ÕªÒªÉÏ´«µÄtxtÎļþ¡£ÔÚ¸Ã±íµ¥ÖУ¬ÎÒÃÇʹÓá°form¡±±êÇ©°ü×°ÎļþÉÏ´«ÊäÈë¿ò¡£

´¦Öóͷ£ÉÏ´«ÇëÇó

µ±Óû§Ñ¡ÔñÁËÒªÉÏ´«µÄtxtÎļþ²¢Ìá½»±íµ¥Ê±£¬ÐèÒªÔÚЧÀÍÆ÷¶Ë´¦Öóͷ£ÉÏ´«ÇëÇó¡£¹ØÓÚthinkphp¿ò¼Ü¶øÑÔ£¬¿ÉÒÔʹÓá°Request¡±¹¤¾ßÀ´»ñÈ¡ÉÏ´«µÄÎļþ¡£

¶ÁÈ¡ÎļþÄÚÈݲ¢½«Æä´æ´¢µ½Êý¾Ý¿â

ÔÚ»ñÈ¡µ½ÉÏ´«µÄÎļþºó£¬ÎÒÃÇÐèÒª¶ÁÈ¡¸ÃÎļþµÄÄÚÈݲ¢½«Æä´æ´¢µ½Êý¾Ý¿âÖС£¹ØÓÚtxtÎļþ¶øÑÔ£¬ÎÒÃÇ¿ÉÒÔʹÓÃPHPÄÚÖõġ°file_get_contents()¡±º¯ÊýÀ´¶ÁÈ¡ÎļþÄÚÈÝ¡£È»ºó£¬ÎÒÃÇ¿ÉÒÔʹÓÃthinkphp·â×°µÄ¡°Db¡±ÀàÀ´ÏòÊý¾Ý¿âÖвåÈëÒ»Ìõеļͼ¡£

Á¬Ã¦Ñ§Ï°¡°PHPÃâ·ÑѧϰÌõ¼Ç£¨ÉîÈ룩¡± £»

ÒÔÏÂÊÇÍêÕûµÄÉÏ´«´úÂ룺

£¨1£©½¨ÉèÊý¾Ý¿â±í

CREATE TABLE txt_data (

id int(11) NOT NULL AUTO_INCREMENT,

content text NOT NULL,

PRIMARY KEY (id)

) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8mb4;

£¨2£©½¨ÉèÉÏ´«±íµ¥

ÉÏ´«

£¨3£©´¦Öóͷ£ÉÏ´«ÇëÇó

public function upload()

{

$file = request()->file('txt_file');
$content = file_get_contents($file->getRealPath());

$data = [
   'content' => $content
];

$result = Db::table('txt_data')->insert($data);

if ($result) {
    return 'ÉÏ´«ÀÖ³É';
} else {
    return 'ÉÏ´«Ê§°Ü';
}

µÇ¼ºó¸´ÖÆ

}

×ܽ᣺

ÔÚ±¾ÎÄÖУ¬ÎÒÃÇѧϰÁËÔõÑùʹÓÃthinkphp¿ò¼Ü½«txtÎļþÉÏ´«µ½Êý¾Ý¿â¡£Ïêϸ¶øÑÔ£¬ÎÒÃǽ¨ÉèÁËÒ»¸öÃûΪ¡°txt_data¡±µÄÊý¾Ý¿â±íÀ´´æ´¢ÉÏ´«µÄtxtÎļþÄÚÈÝ£¬È»ºó½¨ÉèÁËÒ»¸öÉÏ´«±íµ¥£¬²¢ÔÚЧÀÍÆ÷¶Ë´¦Öóͷ£ÁËÉÏ´«ÇëÇó¡£×îºó£¬ÎÒÃÇʹÓá°file_get_contents()¡±º¯Êý¶ÁÈ¡ÉÏ´«µÄtxtÎļþÄÚÈÝ£¬²¢Ê¹Óá°Db¡±ÀཫÆä´æ´¢µ½Êý¾Ý¿âÖС£

ÒÔÉϾÍÊÇthinkphpÔõôÉÏ´«txtµ½Êý¾Ý¿âµÄÏêϸÄÚÈÝ£¬¸ü¶àÇë¹Ø×¢±¾ÍøÄÚÆäËüÏà¹ØÎÄÕ£¡

ÃâÔð˵Ã÷£ºÒÔÉÏչʾÄÚÈÝȪԴÓÚÏàÖúýÌå¡¢ÆóÒµ»ú¹¹¡¢ÍøÓÑÌṩ»òÍøÂçÍøÂçÕûÀí£¬°æȨÕùÒéÓë±¾Õ¾Î޹أ¬ÎÄÕÂÉæ¼°¿´·¨Óë¿´·¨²»´ú±í×ðÁú¿­Ê±ÂËÓÍ»úÍø¹Ù·½Ì¬¶È£¬Çë¶ÁÕß½ö×ö²Î¿¼¡£±¾ÎĽӴýתÔØ£¬×ªÔØÇë˵Ã÷À´ÓÉ¡£ÈôÄúÒÔΪ±¾ÎÄÇÖÕ¼ÁËÄúµÄ°æȨÐÅÏ¢£¬»òÄú·¢Ã÷¸ÃÄÚÈÝÓÐÈκÎÉæ¼°ÓÐÎ¥¹«µÂ¡¢Ã°·¸Ö´·¨µÈÎ¥·¨ÐÅÏ¢£¬ÇëÄúÁ¬Ã¦ÁªÏµ×ðÁú¿­Ê±ÊµÊ±ÐÞÕý»òɾ³ý¡£

Ïà¹ØÐÂÎÅ

ÁªÏµ×ðÁú¿­Ê±

18523999891

¿É΢ÐÅÔÚÏß×Éѯ

ÊÂÇéʱ¼ä£ºÖÜÒ»ÖÁÖÜÎ壬9:30-18:30£¬½ÚãåÈÕÐÝÏ¢

QR code
¡¾ÍøÕ¾µØͼ¡¿¡¾sitemap¡¿