• 欢迎访问搞代码网站,推荐使用最新版火狐浏览器和Chrome浏览器访问本网站!
  • 如果您觉得本站非常有看点,那么赶紧使用Ctrl+D 收藏搞代码吧

一段下传图片,并在MYSQL中记录路径的代码求指正

php 搞代码 3年前 (2022-01-24) 14次浏览 已收录 0个评论

一段上传图片,并在MYSQL中记录路径的代码求指正
只上传一张图片的功能已经实现,上传两张图片就实现不了,代码段比较简单,麻烦大家指导一下:

上传图片的表单:

PHP code

<!---ecms Code highlighting produced by Actipro CodeHighlighter (freeware)http://www.CodeHighlighter.com/--><?phpif ( isset($_GET['action']) && $_GET['action'] == "save" ){include_once('conn.php');  //连接数据库include_once('uploadclass.php');//这个文件在下文会给出$pic=$uploadfile;   //第一张图片,已经可以正常上传$pic2=$uploadfile2; //第二张,上传不了$sql="insert into product (pic,pic2) values ('$pic','$pic2')";$result=mysql_query($sql,$conn);if   (!$result){      echo mysql_error();      echo $sql;      exit;}else{      echo"<script>window.alert('congratulations,the product data inserted successful');location.href='index.php'</script>";} mysql_close();}?><meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /><title>Administrator for upload the product resource</title><body>Images_1:                           <br />Images_2:                           <p />              

上传程序:uploadclass.php(此程序只能上传图片1,如果要能上传图片2,需要怎么加代码呢?)

PHP code

<!---ecms Code highlighting produced by Actipro CodeHighlighter (freeware)http://www.CodeHighlighter.com/--><?php$uploaddir = "../images/upfiles/";$type=array("jpg","gif","bmp","jpeg","png");$patch="aloesky/";function fileext($filename){return substr(strrchr($filename, '.'), 1);}function random($length){$hash = 'CR-';$chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ0123<mark style="color:transparent">本文来源gaodaimacom搞#^代%!码&网*</mark><pre>搞代gaodaima码

456789abcdefghijklmnopqrstuvwxyz’;$max = strlen($chars) – 1;mt_srand((double)microtime() * 1000000);for($i = 0; $i < $length; $i++){$hash .= $chars[mt_rand(0, $max)];}return $hash;}$a=strtolower(fileext($_FILES['file']['name']));if(!in_array(strtolower(fileext($_FILES['file']['name'])),$type)){$text=implode(",",$type);echo "You can only upload the following types of files:",$text,"
return and try again?click me”;exit;}else{$filename=explode(“.”,$_FILES[‘file’][‘name’]);do{$filename[0]=random(10); $name=implode(“.”,$filename);//$name1=$name.”.Mcncc”;$uploadfile=$uploaddir.$name;}while(file_exists($uploadfile));if (move_uploaded_file($_FILES[‘file’][‘tmp_name’],$uploadfile)){if(is_uploaded_file($_FILES[‘file’][‘tmp_name’])){echo “the Images Upload failed!”;}else{echo “Your file has been uploaded:
“;echo “
Continue to upload”;}}}?>

——解决方案——————–

探讨

引用:

这样当成数组就好处理了。
php端: print_r($_FILES[‘file’]); //得到一个二维数组,只需处理数组即可.


搞代码网(gaodaima.com)提供的所有资源部分来自互联网,如果有侵犯您的版权或其他权益,请说明详细缘由并提供版权或权益证明然后发送到邮箱[email protected],我们会在看到邮件的第一时间内为您处理,或直接联系QQ:872152909。本网站采用BY-NC-SA协议进行授权
转载请注明原文链接:一段下传图片,并在MYSQL中记录路径的代码求指正
喜欢 (0)
[搞代码]
分享 (0)
发表我的评论
取消评论

表情 贴图 加粗 删除线 居中 斜体 签到

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址