Home > Backend Development > PHP Tutorial > Use PHP to process image file uploads

Use PHP to process image file uploads

不言
Release: 2023-03-29 15:16:02
Original
3665 people have browsed it

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">
Copy after login

Code:


添加商品

<form action="goods/goodsAdd.action.php" method="POST" enctype="multipart/form-data">
  • 产品分类

  • 货架

Copy after login

View data:

    echo "<pre class="brush:php;toolbar:false">";

      print_r($_POST);

      echo "
"; echo "
";

      print_r($_FILES);

      echo "
"; exit;
Copy after login


The test is as shown:


. PHP file code:

<?php
  
	require(&#39;../../public/common/config.php&#39;);

      // 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"; } ?>
Copy after login

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!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template