时间:2021-07-01 10:21:17 帮助过:19人阅读
PHP上传文件代码
- php
- $file=$_FILES['userfile1']['tmp_name'];
- $filename=$_FILES['userfile1']['name'];
- $x=rand(1000,9999);
- $tmp_add_pd_path="./upload/".$x.".jpg";
- if(!$file||$file=="none"){
- echo"no";
- }
- else{
- if(move_uploaded_file($file,$tmp_add_pd_path)){
- echo$filename;
- $db=mysql_connect("localhost","root","wyh7ye");
- mysql_select_db("test",$db);
- $query="INSERTintoproduct(name)values('$tmp_add_pd_path')";
- $result=mysql_query($query,$db);
- $pid="SELECTLAST_INSERT_ID()";
- $pid_result=mysql_query($pid,$db);
- $rows=mysql_fetch_array($pid_result);
- $tmp_pid=$rows[0];
- $tmp_p_type_sql="INSERTintot_product(typeid,pid)values('$p_type','$tmp_pid')";
- $result=mysql_query($tmp_p_type_sql,$db);
- echo"sucess";
- }
- else{
- echo"false";
- }
- }
- ?>
- <br><br><br><br>
- php
- $db=mysql_connect("localhost","root","wyh7ye");
- mysql_select_db("test",$db);
- $query="selectnamefromproduct";
- $result=mysql_query($query,$db);
- while($rows=mysql_fetch_array($result)){
- echo"<imgsrcimgsrc=".$rows['name']."width=180180height=180><br>";
- }
- ?>
以上就是详细的PHP上传文件代码,希望对大家有帮助。
http://www.bkjia.com/PHPjc/446558.htmlwww.bkjia.comtruehttp://www.bkjia.com/PHPjc/446558.htmlTechArticlePHP还是比较常用的,相信大家也都知道它的好处,给大家演示一个PHP上传文件代码,下面我们来一起看看吧。通过memory_limit变量来指定单个...