Free and Unlimited Web Hosting

Why are my files deleted after uploading them?

Why are my files deleted after uploading them?

Sometimes, when you upload a file, the upload is completed but the file is deleted immediately afterwards. This is usually caused by one of the following issues:

The file is not in a htdocs folder

All websites files must be uploaded to either the main htdocs folder, or to the domain specific htdocs folder (like example.com/htdocs).

You cannot upload files to other directories on your account. If you try to create or upload files anywhere else, they will be deleted automatically.

The file type is not allowed

Certain file types, like .exe files, are blocked on InfinityFree for security and fair usage limitations. Regular website files are allowed, but other files may be blocked.

If you would like to offer something for download or embed a video in your website, please use a specialized file sharing service or video streaming service for that instead.

The file contains malware

Uploaded files are automatically scanned for malware. If malware is detected in a file, it’s automatically deleted to prevent damage to your website and your visitors.

The file is bigger than 10 MB

There is a file size limit of 10 MB on our servers. If you try to upload a file bigger than 10 MB to your account, it will be deleted.

Please note that this is a file size limit, not just a PHP upload limit. All files on your account are subject to this limit, regardless of how you’re trying to get this file on your account.

If this is the problem you experience, please see the article How to upload big files for workarounds.

The file is a .htaccess file larger than 10 kB

In addition to the general file size limit, there is a limit of 10 kB for .htaccess files. A .htaccess file larger than 10 kB will automatically be deleted.

A large .htaccess file can negatively impact server performance which can slow down your website and the website of others. So using large .htaccess files should be avoided in general.

Below are a few common use cases for large .htaccess files and ways to work around them.

You want to block bad bots from accessing your website

One common way to block bad bots is filtering and blocking access to specific User Agent information sent by the client.

Such .htaccess rules are typically of limited use and should be removed, for multiple reasons:

  • User agents are freely configurable by the client, and many bad bots pretend to be popular browsers on common operating systems, which can’t be caught by such filters.
  • Free hosting already comes with a security system to keep out bots, which works more effectively than a user agent filter.

So you can safely remove these lines and know that your website is already protected in more effective ways.

You want to restrict access to certain countries

If you want to restrict access to your website to certain countries (either blacklisting or whitelisting certain regions), one such way is to only allow or deny access to IP addresses in certain ranges.

You can deal with this by moving the IP blacklisting/whitelisting to PHP code, from where you can also filter IP addresses.

But it should be noted that using IP ranges for country restrictions is an inherently flawed method. IP ranges are assigned to network operators, who can then use those IP addresses wherever they want, or even use them in multiple locations at the same time. It’s impossible to have a definitive list detailing which IP address ranges belong to which country.

From PHP, you can also use a GeoIP service to get more accurate location information about specific IP addresses.

And finally, from your PHP code, it’s much easier to customize what people will see if they are blocked. With a .htaccess file, they would only see a generic “403 Forbidden” page.

You have a complex set of rewrite rules

If you’re written your own software, you may have a large set of rewrite rules to send specific URLs to specific pages. This is an acceptable way to handle routing in your application, but may lead to very large .htaccess fles as your application grows bigger.

Most frameworks and CMS handle routing from within PHP. So all page requests are redirected to single index.php file, from where PHP code selects which code to execute for the requested URL.

The file is a HTML or PHP file larger than 1 MB

In addition to the general file size limit, there is a limit of 1 MB for HTML and PHP files. Any HTML or PHP code file larger than this will automatically be deleted after uploading it.

Depending on the contents of your PHP/HTML file, you may be able to reduce the file size in one of the following ways:

  • If you have a large amount of CSS and Javascript code in the file, consider moving this code to separate files and linking them from the same page. This will also help speed up your website, because separate CSS and Javascript files can be cached more effectively.
  • If the HTML page contains a lot of data to be displayed to visitors, you may be able to move this data to separate text files or a MySQL or SQLite database which can be queried from PHP.
  • If the file contains a lot of PHP code, you may be able to move some of this code to separate files, and use PHP include or require directives to combine the code in a single process. This also makes it easier to reuse code across multiple pages, and generally makes it easier to read and understand.
  • If the file contains a lot of HTML code, you can also use PHP include or require directives to combine multiple HTML files, like headers and footers, into a single page. However, note that having a very large HTML page means it may be very slow to load for people and use a lot of bandwidth, which is bad for (mobile) users. So you may also wish to consider to restructure your website so spread the content over multiple, specific pages.
Still have questions? Check our forum!

Forget the stereotypes of free hosting!