How to upload images with restrictions? Those. Need restrictions on file size and image. It is necessary that when you click a picture, for example, with a size of 200 * 200 and a file size!

#picture{ border:1px solid; background-color:#FFF; overflow: hidden; } .picture{ width:460px; height:600px; } #imageFace{ background:url("../images/faces/Face_3.jpg") no-repeat bottom; background-size:100%; z-index:-1; } .button{ width:60px; height: 100px; } 
 <div class="grid_6 prefix_3 suffix_3"> <div id="picture" class="picture"> <div id="imageFace" class="picture"></div> </div> </div> <p><button id="save" class="button" onload="imgLoaded(this)" onClick="javascript:savePicture();">Save Picture</button></p> 

  • one
    The check is done on the server, not on the client - Alexey Shimansky
  • On the client, you can check only the file size. here is an example of kavoir.com/2009/01/... what is no. - nick_n_a
  • Well, it means the file size, tried to google, but not google ( - incub

1 answer 1

By means of the client, it is not possible to perform this task, since it is impossible to directly access the file system from the browser. Checks of this kind are always carried out on the server side. The file is downloaded as a stream to the server, if the download process detects that the file has exceeded the allowed file size, it stops loading and returns an error code. If the file is within the size, it is brought to the image (as, it already depends on the type of backend you are using), then the raster dimensions are checked and if they do not meet the requirements, an error code is returned.

  • And how to do without checking? Just pushing a button? Found this code, but how to simulate the input type file, but when you click on the button: $ (document) .ready (function () {$ ("# save"). Click (function () {$ ("# div1") .load ("demo_test.txt");});}); - incub
  • The $ (). Load function loads a file in the container into the container. In the example you give, it loads into the div demo_test.txt by the relative path domain / demo_test.txt . This way you cannot download the file from the client’s local machine. - Oleg Vyalkin