I've been reading upload uploading image files to a mysql database. And that they have a max of 1 mb. Furthermore there's a time out of 30 seconds in php. In order to do uploads larger dan 1 mb I should edit some mysql and php settings.

But what if that is all installed by my hosting company and I can't change any php.ini or mysql settings? Is there still a way to create an upload script which allows large files to be uploaded?

    1. The upload_max_filesize directive can be changed via an .htaccess file assuming a) your host is running Apache, b) PHP was installed as an ISAPI module (not a CGI binary), and c) your host allows you to use .htaccess files. Alternatively, some hosts have PHP configured such that a php.ini in the root of your account will be parsed for configurations.

    2. Before you start getting into the various configurations (e.g. timeouts; I'm not quite sure where you're getting the "max of 1 mb" for MySQL...), you might want to ask yourself if you even need to bother.

    Why store the file in the database? Why not just use the filesystem handle storing the file, and just use the database to store relevant information (e.g. the path to the image, the image's size, etc.)?

      Yes, thinking about it that would indeed be better. Then I would develop a php upload script. Storing the uploaded file somewhere on the server in e.g. a 'uploads' folder. And I would place the link to it in the database.
      But talking about php uploading, I've read that the 30 seconds default timeout for the execution of scripts could be a problem? Would that mean that when someone would upload a 8 mb file, the script would stop after 30 seconds? If so, what could I do about it besides editing the php.ini file? (cause that's on the hosting company's server so I don't have access to it)

        For one, the 30 second execution time can be changed using [man]set_time_limit/man, but that doesn't apply in this situation; the PHP script isn't even executed until the client has finished uploading the file.

        EDIT: Perhaps I was mistaken. Either way, you could increase the max_execution_time and max_input_time directives as described in this article just to be sure.

        EDIT2: Ah, found the reference in the manual ([man]file-upload.common-pitfalls[/man]):

        PHP Manual wrote:

        Note: max_execution_time only affects the execution time of the script itself. Any time spent on activity that happens outside the execution of the script such as system calls using system(), the sleep() function, database queries, time taken by the file upload process, etc. is not included when determining the maximum time that the script has been running.

        Thus you only should worry about directives such as max_input_time, post_max_size, upload_max_filesize, etc.

          Write a Reply...