0

I would like to know if its possible to set a timelimit/timeout to a script in php..

ex: I have a script to update my avatar, and I would like to know if it's possible when a user tries to insert a LARGE file, if it's taking too long, show an message or redirect to another page saying try to insert an smaller file

5
  • Define LARGE file? What is your size? Commented Oct 21, 2016 at 22:18
  • actually doesn't matter, my LARGE means, taking too long, just that, if its taking more than 10 seconds to upload, show an message or redirect Commented Oct 21, 2016 at 22:19
  • I strongly suggest that you should check the image size to handle this. Time is not accurate and enough data to redirect user. You can use the getimagesize function on php. Commented Oct 21, 2016 at 22:20
  • What may take 10 seconds may take 1 second depending on the user's upload speed. Time is not an accurate constraint here. You need to go with a file size limit for this stuff. Commented Oct 21, 2016 at 22:21
  • But, think with me guys.. If the user tries to upload an large .mp4 file (even i'm just allow .jpg .png and .jpeg files) the .mp4 will load until 100% and just after that will give an message files allowed: ... FOR THAT i wanted this... If they try to upload a large file, "kill" it after 10 seconds Commented Oct 21, 2016 at 22:25

2 Answers 2

3

you can use the PHP function set_time_limit($seconds)

Sign up to request clarification or add additional context in comments.

Comments

2

There are config settings for PHP that measure the file size: max_file_upload max_upload_size

Update those to the maximum file size you'll accept and then PHP will do the rest.

1 Comment

BUT the thing is: if the user tries to upload an .mp4 file, the file will load until 100% and just after that will show an message saying an error.. My ideia was after 5 or 10 seconds after it (to not take a lot of time loading the file) just redirect the user to other page

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.