There is a script that uploads pictures to the server and it writes the path to the database. Can you please tell me how to make each downloadable image automatic 200 * 200, so that you do not constantly do it all the time manually? there is WideImage how it can be implemented in this code

<html> <head> <title>Добавление obj файлла</title> </head> <body> <form action="load.php" enctype="multipart/form-data" method="post"> <input type="file" name="img"> <a><input type="submit" name="add" value="Загрузить"></a> <a href="index.php">Вернуться</a> </form> <?php include('set.php'); include ('lib/WideImage.php'); $path = 'scr/'; $ext = array_pop(explode('.',$_FILES['img']['name'])); $pic = array_pop(explode('.',$_FILES['img']['name'])); $new_name = date("dmY").'-'.$_FILES['img']['name']; $full_path = $path.$new_name; echo $new_name; echo '<br>'; echo $full_path; if($_FILES['img']['error'] == 0){ if (($pic!="jpg") && ($pic!="png") && ($pic!="jpeg")){ echo "Файл не был загружен, загрузите файл с расширением .jpeg/jpg/png"; exit(); } else { $image = WideImage::load($new_name); $resized = $image->resize(200, 200); $resized->saveToFile($full_path); if(move_uploaded_file($_FILES['img']['tmp_name'], $full_path)){ } } } if(isset($_POST['add'])) { $result = mysql_query(' INSERT INTO obj (`img`) VALUES ("' . $full_path . '") '); mysql_close; echo "Картинка добавлена"; } ?> 

Produces such an error

Warning: file_get_contents (12/21/2016-1.jpg) [function.file-get-contents]: failed to open stream: No such file or directory in Q: \ home \ localhost \ www \ test \ lib \ WideImage.php on line 195

Warning: unpack () [function.unpack]: Type c: not enough input, need 1, have 0 in Q: \ home \ localhost \ www \ test \ lib \ vendor \ de77 \ TGA.php on line 93

Fatal error: Uncaught exception 'WideImage_InvalidImageSourceException' with message 'File '21. 12.2016-1.jpg' appears to be an invalid image source. ' in Q: \ home \ localhost \ www \ test \ lib \ WideImage.php: 226 Stack trace: # 0 [internal function]: WideImage :: loadFromFile ('21. 12.2016-1.jp ... ') # 1 Q : \ home \ localhost \ www \ test \ lib \ WideImage.php (184): call_user_func (Array, '21 .12.2016-1.jp ... ') # 2 Q: \ home \ localhost \ www \ test \ load .php (42): WideImage :: load ('21 .12.2016-1.jp ... ') # 3 thrown in Q: \ home \ localhost \ www \ test \ lib \ WideImage.php on line 226

1 answer 1

Found the answer to your question here.

$res = $pic->resize(250, 1000);

It will require PHP 5.2+ and the GD WideImage library

  • I'll try, tell you about the result) thanks! - Michael
  • $ res = $ pic-> resize (250, 1000); I only need this line? - Michael
  • and how can I add this to myself include 'lib / WideImage.php'; $ image = WideImage :: load ("1.jpg"); $ resized = $ image-> resize (200, 200); $ resized-> saveToFile ("1small.jpg"); I understand that instead of 1.jpg and 1small.jpg you need your own variables or what? - Michael
  • @Michael Yes, use whatever you want - ThusMad
  • @Michael more precisely the file names received from the client can be renamed for convenience - ThusMad