Skip to content
Advertisement

Renaming files with random string after upload and storing the name in array

I’m trying to process multiple files upload with foreach then rename the files with random string and store the file names in an array, here’s my current code:

JavaScript

I can’t find where the problem is, should I use foreach for every generated file name then use move_uploaded_file inside the foreach?

Advertisement

Answer

You are completely wrong. You have initialized $_FILES['files']['name'] in the foreach statement and trying to access $_FILES['files']['error'] and $_FILES["files"]["tmp_name"] in each iteration. Since this is an array it not possible.

So solution is as follows,

JavaScript

Hope this can help you.

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