这篇文章主要介绍了关于用PHP处理图片文件的上传,有着一定的参考价值,现在分享给大家,有需要的朋友可以参考一下
1.html文件
form表单注意。enctype属性
代码:<?php
require('../../public/common/config.php');
$sqlClass = "select * from sort";
$rstClass = mysqli_query($conn,$sqlClass);
?>
添加商品
商品名
商品价格
商品库存
产品分类
while ($rowClass=mysqli_fetch_assoc($rstClass)) {
echo "{$rowClass['name']}";
$sqlBrand = "select * from brand where sort_id='{$rowClass[id]}' ";
$rstBrand = mysqli_query($conn,$sqlBrand);
while ($rowBrand=mysqli_fetch_assoc($rstBrand)) {
echo " |-{$rowBrand['name']}";
}
}
?>
货架
上架s
下架d
查看数据:echo "
";
print_r($_POST);
echo "
";echo "
";
print_r($_FILES);
echo "
";exit;
测试如图:
。php文件代码:<?php
require('../../public/common/config.php');
// echo "
";
// print_r($_POST);
// echo "
";// echo "
";
// print_r($_FILES);
// echo "
";// exit;
$name = $_POST['goodsname'];
$price = $_POST['goodsprice'];
$sort = $_POST['goodsort'];
$shelf = $_POST['shelf'];
$brand_id = $_POST['brand_id'];
//图片上传
$src = $_FILES['img']['tmp_name'];
$name = $_FILES['img']['name'];
$ext = array_pop(explode('.', $name));
$dst = '../../public/uploads/'.time().mt_rand().'.'.$ext;
if(move_uploaded_file($src, $dst)){
echo "upload success";
//图片缩放200*200
}else{
echo "upload error";
}
?>
相关推荐: