Jump to content

Tamanho do ficheiro para upload...


nuno_couto

Recommended Posts

Boas.

Num formulário html que envia um ficheiro para um script PHP para que seja guardado no servidor, sei que é possível limitar o tamanho do ficheiro no script, mas, para verificar esse tamanho, o ficheiro já foi enviado, sobrecarregando desnecessáriamente o servidor, e fazendo o utilizador esperar durante o tempo do upload.

Penso que com um java script será possível limitar o tamanho do ficheiro logo no formulário.

Alguem sabe ajudar? Obrigado.

portalmundial.net »» criamos sites

Link to comment
Share on other sites

Não, isso não será possível:

The browser security does not allow the scripts (Javascript/VBScript) or even applets and ActiveX Controls to read files from the local hard disk. You can only read files if your code is signed by some Certificate Authority (CA). Now the input type "FILE" also does not have the permission to read files. We cannot do anything about that since thats what HTML says. So since it cannot read files, it cannot find the size of the file with which the input tag is associated. Since it cannot find the file size, there is no function exposed by JavaScript/VBScript to return the file size. But if you need to find the file size, say in order to restrict the size of the file uploaded to your web-server. Then you can do so by counting the file contents on the server-side, once the user submits it to the server. Thats what many of the free e-mail providers like www.hotmail.com do.
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...

Important Information

By using this site you accept our Terms of Use and Privacy Policy. We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.