Problem:
Learn to use the TP framework to do e-commerce website is, add product form need to upload merchandise logo and product image pics, there are two upload domain, the first upload domain is logo, only upload one, the second upload domain is pics, upload multiple pictures. Use the following code, always error: illegally upload files!
$upload = \think\upload; $info=$upload->upload ();
Workaround:
When you have multiple upload domains, you should use the upload method as follows to specify the upload domain to process:
$upload = \think\upload; $info 1 = $upload->upload (' logo ' =>$_files[' logo '); $info 2 = $upload->upload ( Array (' pics ' =>$_files[' pics ');
Resources:
Title:
T p frame upload picture times wrong "illegal upload" processing
Content:
TP frame upload picture times wrong "illegal upload" processing, the main attention to the following two points:
1.$_files There are multiple upload domain issues, so for different upload domain, the name of the difference;
2. As in the upload domain there are some not uploaded images, you want to re-collect the uploaded information (collected into a non-empty one-dimensional array);
The specific code is as follows;
First case:
if($this-_hasimg ())02. { 03.//only upload a picture of name named Jqimg in the form04.$info=$upload->upload (Array(' jqimg ' =$_files[' Jqimg '])); 05.if(!$info) Redirect (U (' Ad/ad/save/id/').$ad _id), 3,$upload-GetError ()); 07.//loop each picture, insert into the Jq-info table08.foreach($info as$k=$v) 09. { 10.$url=$v[' Savepath '].$v[' Savename ']; 11.$this->execute ("INSERT into Sh_ad_jq_info (img_url,ad_link,ad_id) VALUES ('$url','{$_post[' Jqtxt '] [$k]}',$ad _id)"); 12. } 13. } 14.//working with modified pictures15.if(isset($_post[' Oldjqtxt '])) 16. { 17.//First upload image modified pictures18.$info=$upload->upload (Array(' oldjqimg ' =$_files[' Oldjqimg '])); 19.$_k= 0; 20.foreach($_post[' Oldjqtxt '] as$k=$v) 21st. { 22.//did you upload a new picture ?23.if($info&&isset($info[$_k])) 24. { 25.//upload a new image26.//Delete the original image first27.$_ourl=$this->query (' SELECT img_url from sh_ad_jq_info WHERE id = '.$k); 28. @unlink(IMG_URL_HD.$_ourl[0] [' Img_url ']); 29.//update to new diagram30.$_url=$info[$_k[' Savepath '].$info[$_k[' Savename ']; 31.$this->execute ("UPDATE sh_ad_jq_info SET ad_link="$v', Img_url= '$_url' WHERE id=$k"); 32. } 33.Else34. { 35.$this->execute ("UPDATE sh_ad_jq_info SET ad_link="$v' WHERE id=$k"); 36. } 37.$_k++; 38. } 39. } 40.}
Second case:
foreach($_files[' Imgjq_url '] [' Tmp_name '] as$k=$v) 02. { 03.04.if($v) 05. { 06.//Delete an existing hard drive picture07.$img _url=$this->query ("Select Imgjq_url from sh_ad_jq_info WHERE id =$k"); 08.09. @unlink(IMG_URL_HD.$img _url[0] [' Imgjq_url '] ); 10.11. 12.//Collect picture Information13.$arr=Array(); 14.$arr[' name '] =$_files[' Imgjq_url '] [' Name '] [$k]; 15.$arr[' type '] =$_files[' Imgjq_url '] [' type '] [$k]; 16.$arr[' tmp_name '] =$_files[' Imgjq_url '] [' Tmp_name '] [$k]; 17.$arr[' ERROR '] =$_files[' Imgjq_url '] [' ERROR '] [$k]; 18.$arr[' size '] =$_files[' Imgjq_url '] [' Size '] [$k]; 19.20. 21st.//Upload image processing22.$imgInfo=$upload->upload (Array(' Imgjq_url ' =$arr )); 23.24.if(!$imgInfo) { 25.Echo$upload->geterror (); die; 26. } 27.28.$IMGJQ _url=$imgInfo[' Imgjq_url '] [' Savepath '].$imgInfo[' Imgjq_url '] [' Savename ']; 29.30.//Update to Database31.$this->execute ("UPDATE sh_ad_jq_info SET imgjq_url = ')$IMGJQ _url' WHERE id =$k"); 32.33. } 34.}
The above introduction of the Paladin 5 forward branch TP frame multi-upload domain upload image, including the Paladin 5 before the extension of the content, I hope that the PHP tutorial interested in a friend helpful.