0

update (09 DEC 2017):

I want prevent uploading file more than 100 KB on server from users and during uploading, if the upload volume exceeds 100 kilobytes, stop uploading progress and display warning for user by PHP OR any other script for server-side code.

***OR how can I display an error message to user by getting maximum size of file from php or Apache after set maximum_file_size in php.ini (upload_max_filesize -- post_max_size )OR Apache configuration***

I have an page with php code to upload user's picture for every account.Size of their image file must less than 100 kb size.

how can I stop uploading file if size of temporary file uploaded was more than specific size while uploading is in process By PHP.(e.g. more than 100KB)?? I want make a server-side code to check that rather than client-side.

and a way to set time out in server-side 30 seconds or 1 minutes for uploading.how can I do this?? I'm not very good in php.please help me. Thanks.

Thanks for ALL Answer BUT I want code to run on SERVER and while uploading is in process. Means before finishing uploading on server to avoid the use of bandwidth by hackers and other ,(NOT after uploading), by PHP OR any other script for server-side code

update (09 DEC 2017):

I want prevent uploading file more than 100 KB on server and during uploading, if the upload volume exceeds 100 kilobytes, stop uploading progress and display warning for user by PHP OR any other script for server-side code.

harix
  • 277
  • 3
  • 15
  • Possible duplicate of [How to check file input size with jQuery?](https://stackoverflow.com/questions/1601455/how-to-check-file-input-size-with-jquery) – vijay May 25 '17 at 10:00
  • Is any way to check size of uploaded file when is in process?? – harix May 25 '17 at 14:45
  • thanks for your answer BUT I want code to run **on SERVER** and **while uploading is in process**. Means before finishing uploading upload on server to avoid the use of bandwidth ,**NOT** after uploading, **by PHP OR any other script** for server-side code – harix May 25 '17 at 16:02
  • Bad formattings and many repetitions in your question make it hard to read. – jor Dec 06 '18 at 13:50

1 Answers1

0

PHP:

if($_FILES['fileName']['size'] >  100000) {
   $error = 'Files size should be less than 100KB';
} else{
   move_uploaded_file($_FILES['fileName']['tmp_name'], targetDir);
   //targetDir is your directory where you want to save the file 
}

HTML:

<input type="file" name="fileName" />
vijay
  • 493
  • 5
  • 19
  • thanks for your answer BUT I want to stop uploading file if size of temporary file uploaded was more than specific size **while uploading is in process**. Means before finishing uploading upload on server to avoid the use of bandwidth ,NOT after uploading – harix May 24 '17 at 04:54
  • then you have to use javascript method/jquery for client side before uploading @hariz – vijay May 25 '17 at 09:58
  • use something like `$("#yourFileInput")[0].files[0].size; //jquery` – vijay May 25 '17 at 10:02
  • thanks for your answer BUT I want code to run **on SERVER** and **while uploading is in process**. Means before finishing uploading upload on server to avoid the use of bandwidth ,**NOT** after uploading, **by PHP OR any other script** for server-side code – harix May 25 '17 at 15:58
  • jquery is client side. that is what you are looking for – Jacky Supit Nov 21 '17 at 07:45
  • the above code is for server side, for client side you can use jquery.If you need jquery code I can help you. @harix – vijay Dec 11 '17 at 05:50
  • @vijay I found and used a few JavaScript lines of code, but I would appreciate it if you send a more convenient and more compact code. – harix Dec 14 '18 at 10:07