當前位置:首頁 » 文件管理 » onethink圖片上傳

onethink圖片上傳

發布時間: 2023-05-27 19:53:53

A. onethink,thinkphp 新手,想問一下POST傳參和新加一個前台頁面

index.php?s=/Home/Index/index.html
這個網址的意思是Home模塊的Index控制器的index方法。

文件位置為 /Application/Home/Controller/IndexController.class.php
然後打開這個文件找到index方法

$_POST/$_GET 位置也是按照上面的方法的
假設你需要向 index.php?s=/Home/Index/myaction.html post一個衫物數據
需要在indexController.class.php文件裡面添加一個方法 myaction,,然後在這個方法孫桐裡面處理就可以了。

你可以看一下thinkphp的手則塌坦冊裡面都有介紹的

B. onethink的資料庫配置文件在哪個路徑下

一般分為windows和linux

windows通常放在安裝目錄下的 \Mysql\MySQL Server 5.0\my.ini

Linux 默認是放在 /etc/my.cnf

以下是my.cnf配置文件參數解釋:
[client]
port = 3309
socket = /home/mysql/mysql/tmp/mysql.sock
[mysqld]
!include /home/mysql/mysql/etc/mysqld.cnf #包含的配置文件 ,把用戶名,密碼文件單獨存放
port = 3309
socket = /home/mysql/mysql/tmp/mysql.sock
pid-file = /longxibendi/mysql/mysql/var/mysql.pid
basedir = /home/mysql/mysql/
datadir = /longxibendi/mysql/mysql/var/
# tmp dir settings
tmpdir = /home/mysql/mysql/tmp/
slave-load-tmpdir = /home/mysql/mysql/tmp/
#當slave 執行 load data infile 時用
#language = /home/mysql/mysql/share/mysql/english/
character-sets-dir = /home/mysql/mysql/share/mysql/charsets/
# skip options
skip-name-resolve #grant 時,必須使用ip不能使用主機名
skip-symbolic-links #不能使用連接文件
skip-external-locking #不使用系統鎖定,要使用myisamchk,必須關閉伺服器
skip-slave-start #啟動mysql,不啟動復制
#sysdate-is-now
# res settings
back_log = 50 #接受隊列,對於沒建立tcp連接的請求隊列放入緩存中,隊列大小為back_log,受限制與OS參數
max_connections = 1000 #最大並發連接數 ,增大該值需要相應增加允許打開的文件描述符數
max_connect_errors = 10000 #如果某個用戶發起的連接error超過該數值,則該用戶的下次連接將被阻塞,直到管理員執行flush hosts ; 命令;防止黑客
#open_files_limit = 10240
connect-timeout = 10 #連接超時之前的最大秒數,在Linux平台上,該超時也用作等待伺服器首次回應的時間
wait-timeout = 28800 #等待關閉連接的時間
interactive-timeout = 28800 #關閉連接之前,允許interactive_timeout(取代了wait_timeout)秒的不活動時間。客戶端的會話wait_timeout變數被設為會話interactive_timeout變數的值。
slave-net-timeout = 600 #從伺服器也能夠處理網路連接中斷。但是,只有從伺服器超過slave_net_timeout秒沒有從主伺服器收到數據才通知網路中斷
net_read_timeout = 30 #從伺服器讀取信息的超時
net_write_timeout = 60 #從伺服器寫入信息的超時
net_retry_count = 10 #如果某個通信埠的讀操作中斷了,在放棄前重試多次
net_buffer_length = 16384 #包消息緩沖區初始化為net_buffer_length位元組,但需要時可以增長到max_allowed_packet位元組
max_allowed_packet = 64M #
#table_cache = 512 #所有線程打開的表的數目。增大該值可以增加mysqld需要的文件描述符的數量
thread_stack = 192K #每個線程的堆棧大小
thread_cache_size = 20 #線程緩存
thread_concurrency = 8 #同時運行的線程的數據 此處最好為CPU個數兩倍。本機配置為CPU的個數
# qcache settings
query_cache_size = 256M #查詢緩存大小
query_cache_limit = 2M #不緩存查詢大於該值的結果
query_cache_min_res_unit = 2K #查詢緩存分配的最小塊大小
# default settings
# time zone
default-time-zone = system #伺服器時區
character-set-server = utf8 #server級別字元集
default-storage-engine = InnoDB #默認存儲
# tmp & heap
tmp_table_size = 512M #臨時表大小,如果超過該值,則結果放到磁碟中
max_heap_table_size = 512M #該變數設置MEMORY (HEAP)表可以增長到的最大空間大小
log-bin = mysql-bin #這些路徑相對於datadir
log-bin-index = mysql-bin.index
relayrelay-log = relay-log
relayrelay_log_index = relay-log.index
# warning & error log
log-warnings = 1
log-error = /home/mysql/mysql/log/mysql.err
log_output = FILE #參數log_output指定了慢查詢輸出的格式,默認為FILE,你可以將它設為TABLE,然後就可以查詢mysql架構下的slow_log表了
# slow query log
slow_query_log = 1
long-query-time = 1 #慢查詢時間 超過1秒則為慢查詢
slow_query_log_file = /home/mysql/mysql/log/slow.log
#log-queries-not-using-indexes
#log-slow-slave-statements
general_log = 1
general_log_file = /home/mysql/mysql/log/mysql.log
max_binlog_size = 1G
max_relay_log_size = 1G
# if use auto-ex, set to 0
relay-log-purge = 1 #當不用中繼日誌時,刪除他們。這個操作有SQL線程完成
# max binlog keeps days
expire_logs_days = 30 #超過30天的binlog刪除
binlog_cache_size = 1M #session級別
# replication
replicate-wild-ignore-table = mysql.% #復制時忽略資料庫及表
replicate-wild-ignore-table = test.% #復制時忽略資料庫及表
# slave_skip_errors=all
key_buffer_size = 256M #myisam索引buffer,只有key沒有data
sort_buffer_size = 2M #排序buffer大小;線程級別
read_buffer_size = 2M #以全表掃描(Sequential Scan)方式掃描數據的buffer大小 ;線程級別
join_buffer_size = 8M # join buffer 大小;線程級別
read_rnd_buffer_size = 8M #MyISAM以索引掃描(Random Scan)方式掃描數據的buffer大小 ;線程級別
bulk_insert_buffer_size = 64M #MyISAM 用在塊插入優化中的樹緩沖區的大小。注釋:這是一個per thread的限制
myisam_sort_buffer_size = 64M #MyISAM 設置恢復表之時使用的緩沖區的尺寸,當在REPAIR TABLE或用CREATE INDEX創建索引或ALTER TABLE過程中排序 MyISAM索引分配的緩沖區
myisam_max_sort_file_size = 10G #MyISAM 如果臨時文件會變得超過索引,不要使用快速排序索引方法來創建一個索引。注釋:這個參數以位元組的形式給出.重建MyISAM索引(在REPAIR TABLE、ALTER TABLE或LOAD DATA INFILE過程中)時,允許MySQL使用的臨時文件的最大空間大小。如果文件的大小超過該值,則使用鍵值緩存創建索引,要慢得多。該值的單位為位元組
myisam_repair_threads = 1 #如果該值大於1,在Repair by sorting過程中並行創建MyISAM表索引(每個索引在自己的線程內)
myisam_recover = 64K#允許的GROUP_CONCAT()函數結果的最大長度
transaction_isolation = REPEATABLE-READ
innodb_file_per_table
#innodb_status_file = 1
#innodb_open_files = 2048
innodb_additional_mem_pool_size = 100M #幀緩存的控制對象需要從此處申請緩存,所以該值與innodb_buffer_pool對應
innodb_buffer_pool_size = 2G #包括數據頁、索引頁、插入緩存、鎖信息、自適應哈希所以、數據字典信息
innodb_data_home_dir = /longxibendi/mysql/mysql/var/
#innodb_data_file_path = ibdata1:1G:autoextend
innodb_data_file_path = ibdata1:500M;ibdata2:2210M:autoextend #表空間
innodb_file_io_threads = 4 #io線程數
innodb_thread_concurrency = 16 #InnoDB試著在InnoDB內保持操作系統線程的數量少於或等於這個參數給出的限制
innodb_flush_log_at_trx_commit = 1 #每次commit 日誌緩存中的數據刷到磁碟中
innodb_log_buffer_size = 8M #事物日誌緩存
innodb_log_file_size = 500M #事物日誌大小
#innodb_log_file_size =100M
innodb_log_files_in_group = 2 #兩組事物日誌
innodb_log_group_home_dir = /longxibendi/mysql/mysql/var/#日誌組
innodb_max_dirty_pages_pct = 90 #innodb主線程刷新緩存池中的數據,使臟數據比例小於90%
innodb_lock_wait_timeout = 50 #InnoDB事務在被回滾之前可以等待一個鎖定的超時秒數。InnoDB在它自己的 鎖定表中自動檢測事務死鎖並且回滾事務。InnoDB用LOCK TABLES語句注意到鎖定設置。默認值是50秒
#innodb_flush_method = O_DSYNC
[mysqlmp]
quick
max_allowed_packet = 64M
[mysql]
disable-auto-rehash #允許通過TAB鍵提示
default-character-set = utf8
connect-timeout = 3

C. 六年級上冊英語手抄報圖片簡單又漂亮

1. 英語手抄報圖片簡單又漂亮
英語手抄報圖片簡單又漂亮 英語手抄報又簡單又好看單詞不多
Park There is a park near my home.There are a lot of beautiful trees,flowers and birds in the park.So many people go to the park to enjoy their weekends.They like walking or having a piic in the park.But I like flying a kite with my sisiter there. 我家附近有一個公園.哪裡有很多美麗的樹、花和小鳥.所以很多人都喜歡到那裡去度周末.他們喜歡在公園里散步或是野餐.但是我喜歡和我姐姐在那裡放風箏. Bedroom I have a *** all bedroom.There are only a *** all bed,a *** all desk and a *** all chair in the room.And there is a beautiful doll on my blue bed.Everyday I do my homework,read books and play games with the doll in my bedroom.It is *** all,but it gives me much happiness. 我有一間小小的卧室.那裡有一張小小的床、小小桌子和一把小小的椅子.而且還有一個漂亮的娃娃在我那張藍色的小床上.我每天都在房間里寫作業,看書和與我的娃娃玩.雖然房間很小,但是他給了我很多歡樂. My father My father is a tall and handsome man.He is a policeman. Everyday he es back home very late,because he must help the others.He doesn't have time to examine my homework and take me to the park.But I like my father,because he is a good policeman. 我的爸爸是一個高大帥氣的男人.他是一個警察.他每天都很晚才回家,因為他要幫助其他的人帶褲.他沒有時間給我檢查作業和帶我去公園.但是我仍然很喜歡我的爸爸,因為他是一個好警察. A Fox, just at the time of the vintage, stole into a vine-yard where the ripe sunny Grapes were trellised up on high in most tempting show. He made many a spring and a jump after the luscious prize, but, failing in all his attempts, he muttered as he retreated:"Well what does it matter! The Grapes are sour!" 譯文: 正當葡萄熟了的時候,一隻狐狸偷偷地溜進了葡萄園.葡萄架上高高地掛著亮晶晶的、熟透了的葡萄,顯禪旦得十分誘人.他跳了好幾跳,蹦了好幾蹦,想吃到這甘美的葡萄,但是他的企圖全落空了,走開的時候,他自言自語說:"得了!這有什麼!這葡萄是酸的." 詞彙: trellised up 用棚架支撐著 in most tempting show 最誘人的樣子 A mother's love never changes. 母愛永恆. An apple a day keeps the doctor away. 一天一蘋果,不用請賀行擾醫生. A new broom sweeps clean. 新官上任三把火. An eye for an eye and a tooth for a tooth. 以眼還眼,以牙還牙. An hour in the morning is worth two in the evening. 一日之計在於晨. An old dog cannot learn new tricks. 老狗學不出新把戲. An ounce of luck is better than a pound of wisdom. 聰明才智,不如運氣. An ounce of prevention is worth a pound of cure. 預防為主,治療為輔. A rolling stone gathers no moss. 滾石不生苔,轉業不聚財. As a man sows, so he shall reap. 種瓜得瓜,種豆得豆. A single flower does not make a spring. 一花獨放不是春,百花齊放春滿園. A snow year, a rich year. 瑞雪兆豐年. A sound mind in a sound body.。
英語手抄報簡單又好看春天詩句
Flowers bloom opened,sending out inviting scent,relaxed and happy making a person; Cute little swallow flew from the south,scenery,singing a song.Obviously,three on the steps of light has to hold us!Spring is a rebirth.When the spring rain drip-drip-drip down,like a pearl stood but the earth,wake up the first spring of bamboo shoots,wake up all the life,everything to wake up.Spring is a season of vitality.The arrival of the spring,make the world rejuvenated,restore the aura,restore the vitality.The birds freely in the blue sky to fly,and kept singing songs of joy,as if to wele the arrival of spring.Many plants in spring and grow,bloom,the dance。

Look,the tree out of the green branches; The grass yawn,senses; Bowing with the wind; Bud grin may toward everyone laugh,peach blossom and pear aromas refreshing.Spring is a season of roses.In spring,colorful flowers very charming,plus the bird clear moving singing,and the ubiquity of flowers,as in play a "spring symphony".The butterfly and the honey bee also touched and haste to join the flowers bloom,birds of the debates in the band,a good view of the poetic!"Every dance,play butterfly linger at oriole just cry j." Like fu verse,spring not only glows,or vivid!Let us together to feel the spring,enjoy the spring every a bunch of the warmth of sunshine and rain in the moist,cherish the good time of spring!Listen,ChunLei have rang through the air,"ChunLei a roar,the earth shake three shake." ChunLei is calling you put this beautiful spring describe it!翻譯的內容如下:盛開的花朵開放,散發著誘人的香味,令人心曠神怡;可愛的小燕子從南方飛,風景,唱一首歌.很明顯,三的步驟,光有抱著我們!春天是一個重生.當春雨drip-drip-drip下來,像珍珠站但地球,醒來的竹筍的第一個春天,一覺醒來所有的生命,一切都醒來.春天是生機盎然的季節.春季的到來,使世界重新煥發活力,恢復光環,恢復活力.鳥兒在藍色的天空中自由地飛翔,並繼續唱歡樂的歌,彷彿在歡迎春天的到來.許多植物在春天生長,開花,舞蹈…看,樹上的綠枝上;草地上打哈欠,感覺;鞠躬風;芽咧嘴可能對每個人都笑了,桃花和梨花香氣清新.春天是一個季節的玫瑰.在春季,五顏六色的花朵很迷人,加上鳥清晰動人的歌聲,和無處不在的花,像在玩一個「交響樂之春」.蝴蝶和蜜蜂也感動和匆忙加入鮮花盛開,鳥兒的辯論在樂隊,一個風景好的詩歌!「每一個舞蹈,玩蝴蝶黃鸝只是哭泣〉像杜甫詩句,春天不僅發光,或生動的!讓我們一起去感受春天,享受春天的每一束溫暖的陽光和雨露的滋潤,珍惜春天的好時光!聽著,春雷有響徹雲霄,「春雷轟鳴,大地抖三抖.」春蕾叫你把這美麗的春天的描述!。

春節英語手抄報簡單又好看happy.new year
Spring Festival Chinese New Year is the most important, interesting festival in China. Before the Chinese New Year, everyone is very busy. They want the Spring Festival to be a new beginning, so everyone is busy cleaning the room. They keep the room tidy. This is the first thing to wele the Spring Festival. The elderly take children to buy snacks and fireworks. But parents just stay at home to make tasty meals for dinner. On the evening of New Year's Eve, my parents and my sister have dinner with me. We have a good time. After dinner, Oh! Yeah! My father is ready to give us red pockets. Oh, how nice the red pockets are! My sister and I both all say, 「Peace all year round to my parents! Now, give us red pockets.」 My parents give us the red pockets at once with a *** ile on their faces. What a wonderful time we have! I think 「Everything goes well」 this year!譯文: 春節 中國的新年是最重要的,有趣的節日在中國。

在春節之前,每個人都很忙。他們希望春節是一個新的開始,所以每個人都在忙著打掃房間。

他們保持房間整潔。這是為了迎接春節的第一件事。

老人帶孩子去買零食和煙花。但父母呆在家裡做美味的飯菜吃晚飯。

在除夕晚上,我的父母和我的妹妹和我一起吃晚飯。我們有一個很好的時間。

晚飯後,哦!是啊。我的父親是准備給我們紅色的口袋。

哦,多麼漂亮的紅包!我和妹妹都說,「四季平安給我父母!現在,讓我們紅色的口袋裡。「我的父母給我們紅包一次臉上帶著微笑。

我們有一個多麼美妙的時間! 我認為「一切順利」今年!。
英語繪本手抄報簡單又好看五年級下冊
1 Bring Papa Teacher: For final exam this time, you can take your textbooks, your notebooks, your dictionary etc., just as you do your homework as usual. Frank: That sounds good. Then I can take my papa here. 【譯文】帶爸爸 老師:本次考試,你們可以帶課本、筆記本、詞典等,就像你們平常做作業一樣。

弗里克:太好了,那我就可以把爸爸帶來了。 2 Cat and crab One day, a cat played near the lake. Suddenly, a crab clamped it. The cat is rather cross , it ran after the crab. After a while, that cat ran into the forest. A big brown spider making its in the tree, the cat caught the big brown spider very fast, and the cat said to the big brown spider:" Did you think if you on the , I will not know you? Yes, I still know you?!" 【譯文】貓和螃蟹 一天,一隻貓在湖邊玩耍。

忽然,一隻螃蟹夾了它一下。那隻貓非常生氣,它追著那隻螃蟹跑。

一會兒,它追到了森林裡。一隻大的棕色的蜘蛛正在樹上織網,那隻貓很快地抓住了那隻大的棕色的蜘蛛,並對它說:「小樣兒,你上了網我就不認識你了?!」 Do you like autumn 你喜歡秋天么? I do not know when, you fall softly on my red sweater, you put a flower as I have it? 不知什麼時候,你輕輕地落在我鮮紅的毛衣上,你把我也當成一朵花了嗎? Golden butterfly you! Whom you are dancing in it? Not *** ile flowers, grasses lost their luster. Oh, I see, you are in the garden that little daisy eyes. 金色的蝴蝶呀!你是在為誰而翩翩起舞呢?花兒沒有了笑容,青草失去了光澤。

哦,我明白了,你是在為園子里那眨著眼睛的小雛菊。 Golden butterflies, you are willing to pay my friend? e! Flew into my books, acpanied by bright, I walked into the classroom金色的蝴蝶,你願意和我交朋友嗎?來吧!飛進我的課本,伴著我走進明亮的教室 。

Fall to, chrysanthemum opened. There are red, yellow, with purple, and white, very beautiful! 秋天到了,菊花開了。有紅的,有黃的,有紫的,還有白的,美麗極了! Do you like autumn? 你喜歡秋天嗎? English position英文小作文 My Hobbies I have many hobbies, such as reading, skating, and watching TV. But reading is my favorite hobby. I like reading for three reasons. First of all, books introce me to a new world, which is colorful and with no time and space limit,.Through reading, I can trace back to ancient Egypt, the cradle of human civilization. It can bring myself to the United states, a glamorous land I have been longing to visit. Secondly, reading can improve myself by showing me a new horizon. In the past years, most of my knowledge has been obtained from books. I have learned from many people by reading about their ideas on science, politics, life and society. Thirdly, reading bridges the gap between my dream and my goal. In order to succeed in my career in the future, I must keep reading, thinking and practicing. Reading has bee part of my life. I love reading, 我的愛好

D. Think PHP自帶的上傳文件類,

上傳表單
在ThinkPHP中使用上傳功能無需進行特別處理。例如,下面是一個帶有附件上傳的表單提交:
<form action="__URL__/upload" enctype="multipart/form-data" method="post" >
<input type="text" name="name" />
<input type="file" name="photo" />
<input type="submit" value="提交" >
</form>
注意,要使用上傳功能 你的表單需要設置 enctype="multipart/form-data"
多文件上傳支持
如果需要使用多個文件上傳,只需要修改表單,把
<input type='file' name='photo'>
改為
<input type='file' name='photo1'>
<input type='file' name='photo2'>
<input type='file' name='photo3'>
或者
<input type='file' name='photo[]'>
<input type='file' name='photo[]'>
<input type='file' name='photo[]'>
兩種方式的多附件上傳系統的文件上傳類都可以自動識別。
上傳操作
ThinkPHP文件上傳操作使用Think\Upload類,假設前面的表單提交到當前控制器的upload方法,我們來看下upload方法的實現代碼:
public function upload(){
$upload = new \Think\Upload();// 實例化上傳類
$upload->maxSize = 3145728 ;// 設置附件上傳大小
$upload->exts = array('jpg', 'gif', 'png', 'jpeg');// 設置附件上傳類型
$upload->rootPath = './Uploads/'; // 設置附件上傳根目錄
$upload->savePath = ''; // 設置附件上傳(子)目錄
// 上傳文件
$info = $upload->upload();
if(!$info) {// 上傳錯誤提示錯誤信息
$this->error($upload->getError());
}else{// 上傳成功
$this->success('上傳成功!');
}
}
上傳類對圖片文件的上傳安全做了支持,如果企圖上傳非法的圖像文件,系統會提示 非法圖像文件。 為了更好的使用上傳功能,建議你的伺服器開啟finfo模塊支持
上傳參數
在上傳操作之前,我們可以對上傳的屬性進行一些設置,Upload類支持的屬性設置包括:
屬性 描述
maxSize 文件上傳的最大文件大小(以位元組為單位),0為不限大小
rootPath 文件上傳保存的根路徑
savePath 文件上傳的保存路徑(相對於根路徑)
saveName 上傳文件的保存規則,支持數組和字元串方式定義
saveExt 上傳文件的保存後綴,不設置的話使用原文件後綴
replace 存在同名文件是否是覆蓋,默認為false
exts 允許上傳的文件後綴(留空為不限制),使用數組或者逗號分隔的字元串設置,默認為空
mimes 允許上傳的文件類型(留空為不限制),使用數組或者逗號分隔的字元串設置,默認為空
autoSub 自動使用子目錄保存上傳文件 默認為true
subName 子目錄創建方式,採用數組或者字元串方式定義
hash 是否生成文件的hash編碼 默認為true
callback 檢測文件是否存在回調,如果存在返迴文件信息數組
上面的屬性可以通過兩種方式傳入:
實例化傳入
我們可以在實例化的時候直接傳入參數數組,例如:
$config = array(
'maxSize' => 3145728,
'rootPath' => './Uploads/',
'savePath' => '',
'saveName' => array('uniqid',''),
'exts' => array('jpg', 'gif', 'png', 'jpeg'),
'autoSub' => true,
'subName' => array('date','Ymd'),
);
$upload = new \Think\Upload($config);// 實例化上傳類
關於saveName和subName的使用後面我們會有詳細的描述。
動態賦值
支持在實例化後動態賦值上傳參數,例如:
$upload = new \Think\Upload();// 實例化上傳類
$upload->maxSize = 3145728;
$upload->rootPath = './Uploads/';
$upload->savePath = '';
$upload->saveName = array('uniqid','');
$upload->exts = array('jpg', 'gif', 'png', 'jpeg');
$upload->autoSub = true;
$upload->subName = array('date','Ymd');
上面的設置和實例化傳入的效果是一致的。
上傳文件信息
設置好上傳的參數後,就可以調用Think\Upload類的upload方法進行附件上傳,如果失敗,返回false,並且用getError方法獲取錯誤提示信息;如果上傳成功,就返回成功上傳的文件信息數組。
$upload = new \Think\Upload();// 實例化上傳類
$upload->maxSize = 3145728 ;// 設置附件上傳大小
$upload->exts = array('jpg', 'gif', 'png', 'jpeg');// 設置附件上傳類型
$upload->rootPath = './Uploads/'; // 設置附件上傳根目錄
$upload->savePath = ''; // 設置附件上傳(子)目錄
// 上傳文件
$info = $upload->upload();
if(!$info) {// 上傳錯誤提示錯誤信息
$this->error($upload->getError());
}else{// 上傳成功 獲取上傳文件信息
foreach($info as $file){
echo $file['savepath'].$file['savename'];
}
}
每個文件信息又是一個記錄了下面信息的數組,包括:
屬性 描述
key 附件上傳的表單名稱
savepath 上傳文件的保存路徑
name 上傳文件的原始名稱
savename 上傳文件的保存名稱
size 上傳文件的大小
type 上傳文件的MIME類型
ext 上傳文件的後綴類型
md5 上傳文件的md5哈希驗證字元串 僅當hash設置開啟後有效
sha1 上傳文件的sha1哈希驗證字元串 僅當hash設置開啟後有效
文件上傳成功後,就可以使用這些文件信息來進行其他的數據操作,例如保存到當前數據表或者單獨的附件數據表。
例如,下面表示把上傳信息保存到數據表的欄位:
$model = M('Photo');
// 取得成功上傳的文件信息
$info = $upload->upload();
// 保存當前數據對象
$data['photo'] = $info[0]['savename'];
$data['create_time'] = NOW_TIME;
$model->add($data);
單文件上傳
upload方法支持多文件上傳,有時候,我們只需要上傳一個文件,就可以使用Upload類提供的uploadOne方法上傳單個文件,例如:
public function upload(){
$upload = new \Think\Upload();// 實例化上傳類
$upload->maxSize = 3145728 ;// 設置附件上傳大小
$upload->exts = array('jpg', 'gif', 'png', 'jpeg');// 設置附件上傳類型
$upload->rootPath = './Uploads/'; // 設置附件上傳根目錄
// 上傳單個文件
$info = $upload->uploadOne($_FILES['photo1']);
if(!$info) {// 上傳錯誤提示錯誤信息
$this->error($upload->getError());
}else{// 上傳成功 獲取上傳文件信息
echo $info['savepath'].$info['savename'];
}
}
uploadOne方法上傳成功後返回的文件信息和upload方法的區別是只有單個文件信息的一維數組。
上傳文件的命名規則
上傳文件的命名規則(saveName)用於確保文件不會產生沖突或者覆蓋的情況。命名規則的定義可以根據你的業務邏輯來調整,不是固定的。例如,如果你採用時間戳的方式來定義命名規范,那麼在同時上傳多個文件的時候可能產生沖突(因為同一秒內可以上傳多個文件),因此你需要根據你的業務需求來設置合適的上傳命名規則。這里順便來說下saveName參數的具體用法。
一、採用函數方式
如果傳入的字元串是一個函數名,那麼表示採用函數動態生成上傳文件名(不包括文件後綴),例如:
// 採用時間戳命名
$upload->saveName = 'time';
// 採用GUID序列命名
$upload->saveName = 'com_create_guid';
也可以採用用戶自定義函數
// 採用自定義函數命名
$upload->saveName = 'myfun';
默認的命名規則設置是採用uniqid函數生成一個唯一的字元串序列。
saveName的值支持數組和字元串兩種方式,如果是只有一個參數或者沒有參數的函數,直接使用字元串設置即可,如果需要傳入額外的參數,可以使用數組方式,例如:
// 採用date函數生成命名規則 傳入Y-m-d參數
$upload->saveName = array('date','Y-m-d');
// 如果有多個參數需要傳入的話 可以使用數組
$upload->saveName = array('myFun',array('__FILE__','val1','val2'));
如果需要使用上傳的原始文件名,可以採用__FILE__傳入,所以上面的定義規則,最終的結果是 myFun('上傳文件名','val1','val2')執行的結果。
二、直接設置上傳文件名
如果傳入的參數不是一個函數名,那麼就會直接當做是上傳文件名,例如:
$upload->saveName = time().'_'.mt_rand();
表示上傳的文件命名採用時間戳加一個隨機數的組合字元串方式。
當然,如果覺得有必要,你還可以固定設置一個上傳文件的命名規則,用於固定保存某個上傳文件。
$upload->saveName = 'ThinkPHP';
三、保持上傳文件名不變
如果你想保持上傳的文件名不變,那麼只需要設置命名規范為空即可,例如:
$upload->saveName = '';
一般來說不建議保持不變,因為會導致相同的文件名上傳後被覆蓋的情況。
子目錄保存
saveName只是用於設置文件的保存規則,不涉及到目錄,如果希望對上傳的文件分子目錄保存,可以設置autoSub和subName參數來完成,例如:
// 開啟子目錄保存 並以日期(格式為Ymd)為子目錄
$upload->autoSub = true;
$upload->subName = array('date','Ymd');
可以使用自定義函數來保存,例如:
// 開啟子目錄保存 並調用自定義函數get_user_id生成子目錄
$upload->autoSub = true;
$upload->subName = 'get_user_id';
和saveName參數一樣,subName的定義可以採用數組和字元串的方式。
注意:如果get_user_id函數未定義的話,會直接以get_user_id字元串作為子目錄的名稱保存。
子目錄保存和文件命名規則可以結合使用。
上傳驅動
上傳類可以支持不同的環境,通過相應的上傳驅動來解決,默認情況下使用本地(Local)上傳驅動,當然,你還可以設置當前默認的上傳驅動類型,例如:
'FILE_UPLOAD_TYPE' => 'ftp',
'UPLOAD_TYPE_CONFIG' => array(
'host' => '192.168.1.200', //伺服器
'port' => 21, //埠
'timeout' => 90, //超時時間
'username' => 'ftp_user', //用戶名
'password' => 'ftp_pwd', //密碼 ),
表示當前使用Ftp作為上傳類的驅動,上傳的文件會通過FTP傳到指定的遠程伺服器。
也可以在實例化上傳類的時候指定,例如:
$config = array(
'maxSize' = 3145728,
'rootPath' = './Uploads/',
'savePath' = '',
'saveName' = array('uniqid',''),
'exts' = array('jpg', 'gif', 'png', 'jpeg'),
'autoSub' = true,
'subName' = array('date','Ymd'),
);
$ftpConfig = array(
'host' => '192.168.1.200', //伺服器
'port' => 21, //埠
'timeout' => 90, //超時時間
'username' => 'ftp_user', //用戶名
'password' => 'ftp_pwd', //密碼 );
$upload = new \Think\Upload($config,'Ftp',$ftpConfig);// 實例化上傳類

E. thinkphp主要有什麼用

其實thinkphp是國內自主開發的一款MVC框架,早期是從onethink開始升級而來的。這個框架的話是很符合國人的使用習慣和思維,是作為PHP開發的首要入門級框架,這個框架簡單易用,所以很受企業的歡迎。

接下來回答樓主的答案:

  1. thinkphp既然是一個php的MVC框架,那肯定就是用來快速開發用的,可以用來開發任意一款PHP相關的編碼系統,無論是商城、管理系統還是搭建博客系統等任意系統。

  2. 其次是主要應用在哪個方面比較好,就我目前在企業開發過程中,其實主要應用在企業類、學校類、新聞類系統的開發比較多。其次是開發商城也比較多。主要是開發方便快捷,懂的人多所被接受。

希望我的回答可以幫到你,有什麼不懂可以追問。

F. onethink 安裝出錯了,請問怎麼解決

Errorlaunchinginstaller意思就是安裝程序出錯這說明你可能已經在某個時候手動地把一些文件直接放入回收站了,而不是一開始就點「添加/卸載程序」,而電腦要卸載程序必須要先訪問這些文件後才可以卸載,所以這樣會導致系統無法訪問這些源文件(也就是找不到源文件),自然就無法刪除了。正規操作方式:試試重新下載這個軟體進行安裝,實在不行,你就先在運行中輸入msconfig,選擇啟動,取消非必要啟動項(通常保留殺毒軟體和輸入法就行,或者全部禁用),然後重新啟動,如果還不見效,卸載最近安裝的程序後再試試。其他建議:1、乾脆就直接干到底,找到文件的路徑,然後手動地移到回收站里,也可以達到一樣的效果。2、最好是下載一個優化大師,點擊智能卸載,也可以的。

熱點內容
匯編宏編譯 發布:2025-02-08 16:08:30 瀏覽:191
androidlayoutview 發布:2025-02-08 15:45:01 瀏覽:620
大貨車有哪些安全應急配置 發布:2025-02-08 15:44:55 瀏覽:537
安卓手機下黎明殺機為什麼會閃退 發布:2025-02-08 15:38:27 瀏覽:488
定位演算法源碼 發布:2025-02-08 15:36:43 瀏覽:542
上游伺服器異常什麼意思 發布:2025-02-08 15:15:46 瀏覽:175
如何下載油猴腳本並安裝 發布:2025-02-08 15:02:12 瀏覽:596
硬體哪個配置性價比高 發布:2025-02-08 14:47:07 瀏覽:146
如何去掉僅限自動配置 發布:2025-02-08 14:37:55 瀏覽:708
壓縮空氣有啥 發布:2025-02-08 14:26:01 瀏覽:704