PHP ?? ? MySql ??????? ?? ?? ??? (1)
?? ???? PHP? ???? ??? ????? ??? ?? ????? ??????.
???? ??? ?? ?? ????. ??????? ?? ??? ??? ???? ? ????
??? ?? ??? ?? ??? ???? ????? ????. ??? ?? ??? ?? ????? ? ???? ??? ??? ?????.
???? ??:
?? ???? ? ??? ??? ???? ??? ?? ??? ????
<?php $uploadFiles = array(); ?>
?? ?? foreach ??? ?? ?????
<?php foreach($upfile as $key =>$value) { foreach($value as $k => $v){ $uploadFiles[$k][$key]=$v; } } print_r($uploadFiles); ?>
?? ??? ?????
<?php /* 這里展示同時(shí)上傳2個(gè)文件信息 Array ( [0] => Array ( [name] => 1.png [type] => image/png [tmp_name] => C:\Windows\php82E9.tmp [error] => 0 [size] => 65646 ) [1] => Array ( [name] => 2.png [type] => image/png [tmp_name] => C:\Windows\php82EA.tmp [error] => 0 [size] => 70463 ) ) */ ?>
?????, ?? ???? ?? ??? ?? ?? ??? ??? ?? ??? ???? ?? ?????. ??? ?? ??? ?? ?? ?? ??? ? ?? ??? ???? ???? ??? ??? ?? ?????. ??? ???.
<?php //上傳后的文件名定義(隨機(jī)獲取一個(gè)文件名(保持后綴名不變)) $fileinfo = pathinfo($v["name"]);//解析上傳文件名字 do{ $newfile = date("Y-m-d,H-i-s") . rand(1000, 9999) . "." . $fileinfo["extension"]; } while (file_exists($path . $newfile)); ?>
?? ?????? ???? ???? ??? ????? ?? ??? ? ?? ????
<?php $link = mysqli_connect('localhost','username','password') or die("數(shù)據(jù)庫連接失??!"); mysqli_select_db($link,'test'); mysqli_set_charset($link,'utf8'); $filepath = $path.$newfile; $name = $v['name']; $size = $v['size']; $sql = "insert into img(id,name,size,pic) value(null,'$name','$size','$filepath')"; mysqli_query($link,$sql); mysqli_close($link); ?>