How to load an image with two different names in an input tag using PHP? And change their size

To download the image, I tried the download code of one image twice, but it does not load both images correctly. The first is loading, and the second is not. Here is the code of the used form i:

<form action="" method="post" enctype="multipart/form-data"> <table> <tr><td>Title</td><td><input type="text" name="title" /></td></tr> <tr><td>Date</td><td><input type="text" name="date" /></td></tr> <tr><td>Thumbnail</td><td><input type="file" name="thumb" /></td></tr> <tr><td>Image</td><td><input type="file" name="image" /></td></tr> <tr><td>Details</td><td><textarea name="details"></textarea></td></tr> <tr><td>&nbsp;</td><td><input type="submit" name="Submit" value="Submit" /></td></tr> </table> </form> 
+4
source share
2 answers

On your HTML page use

 <input type="file" name="image[thumb]" /> <input type="file" name="image[image]" /> 

And in PHP catch it like this:

 $_FILES['image']['thumb']; $_FILES['image']['image']; 

Hurrah!

+1
source

To resize the uploaded image, you can try this code: -

 function getWidth() { return imagesx($this->image); } function getHeight() { return imagesy($this->image); } function resize($width,$height) { $new_image = imagecreatetruecolor($width, $height); imagecopyresampled($new_image, $this->image, 0, 0, 0, 0, $width, $height, $this->getWidth(), $this->getHeight()); $this->image = $new_image; } 
+4
source

Source: https://habr.com/ru/post/1403023/


All Articles