Skip to content
Advertisement

Upload, resize and send images to server with javascript

After struggling with this issue for 2 days, reading a lot of material online, here I am begging for your help.

I’m trying to resize some images uploaded via FileReader, resize with canvas and send to my server with php.

Everything works as expected, except when I try to upload multiple files. The script loads only the last image, despite showing base64 data for all images with a console.log ();

I’m missing something that I don’t know what it is.

Here is the code:

JavaScript

As gugateider said, the javascript part its ok.

I think the problem its on the server side. It only saves the last image no mather how much I selecte in the input.

Unfortunately I only have a PHP server, which is enough, but it limits the possibilities of solutions for this technology.

Here is the php code.

JavaScript

Advertisement

Answer

Problem Solved!

I think the round(microtime(true)) wasn’t enough to generate unique names. I changed it to uniqid() and worked.

So the PHP code becomes:

JavaScript
User contributions licensed under: CC BY-SA
6 People found this is helpful
Advertisement