This article mainly introduces the use of PHP to process image file uploads. It has certain reference value. Now I share it with everyone. Friends in need can refer to
1.html file
Form form attention. enctype attribute
<form action="goods/goodsAdd.action.php" method="POST" enctype="multipart/form-data">
Code:
添加商品
<form action="goods/goodsAdd.action.php" method="POST" enctype="multipart/form-data">
产品分类
货架
View data:
echo "<pre class="brush:php;toolbar:false">"; print_r($_POST); echo ""; echo "
"; print_r($_FILES); echo ""; exit;
The test is as shown:
. PHP file code:
<?php require('../../public/common/config.php'); // echo "<pre class="brush:php;toolbar:false">"; // 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"; } ?>
Related recommendations:
php method example of uploading image files in post mode
The above is the detailed content of Use PHP to process image file uploads. For more information, please follow other related articles on the PHP Chinese website!