Home  >  Q&A  >  body text

Problem: Images load too slowly

<p>I used Html, Css, Js, and Php to create a website similar to craiglist. When the user clicks to upload an image larger than 1mb, the page becomes very slow or fails (503 error). There is no problem with images smaller than 100kb. </p> <ol> <li>There is a form with a type=file input tag and a preview img tag on a php page. > No problem here. </li> <li>When the user clicks the submit button, the form passes the value of the input tag to another php page, which contains the upload code. </li> </ol> <p>Question: What is the best way to scale an image before uploading to the server? Compared to Craigslist, my site is very slow or fails to upload images. How to make uploads faster? </p> <pre class="brush:php;toolbar:false;">https://www.mimarketa.com/mmMain/mmEnglish/mmPostAd.php?country=US&county=Lewis&state=WA&adCity=All_Cities& ;category=ALL</pre> <p>I tried searching here and on Google for answers. </p> <p>PHP Page 1: Enter the file tag and image preview tag. JS scales via draw methods. </p> <p>Code of PHP page 2:</p> <pre class="brush:php;toolbar:false;">$upload_dir = "mmAdPics/"; $file1 = $upload_dir . rand() . ".png"; $picUrl1='https://www.mimarketa.com/mmMain/mmEnglish/'.$file1; $img1 = $_POST['hidden_data1']; $img1 = str_replace('data:image/png;base64,', '', $img1); $img1 = str_replace(' ', ' ', $img1); $data1 = base64_decode($img1); $success = file_put_contents($file1, $data1); print $success ? $file1 : 'Unable to save file 1. ';</pre> <p><br /></p>
P粉676821490P粉676821490416 days ago597

reply all(1)I'll reply

  • P粉558478150

    P粉5584781502023-08-18 13:33:54

    Please check: https://www.php.net/manual/en/book.imagick.php

    Specifically, resize the image. Additionally, the 503 error is most likely due to server timeout. You can increase the timeout on the server side, or limit the size of uploaded files on the client side.

    reply
    0
  • Cancelreply