tags:

views:

31

answers:

1

I have a multiple upload form, that renames images after upload:

for ($i = 0; $i < count($_FILES['images']['name']); $i++) {
$ext= end(explode(".",  $_FILES['images']['name'][$i]));
$name =  rand(1111111,9999999).'.'.$ext; 
}

With print_r($name) the output is a string image1.jpgimage2.jpgimage3.jpg. Why the output is a string? How can I give an array? Thanks in advance

+1  A: 
$name[] = rand(1111111,9999999).'.'.$ext;

will do the trick

Bonus:

$ext = pathinfo($_FILES['images']['name'][$i], PATHINFO_EXTENSION);
fabrik
@fabric;Now the output is `Array( [0] => 9292066.jpg)Array( [0] => 9292066.jpg [1] => 5713362.jpg)Array( [0] => 9292066.jpg [1] => 5713362.jpg [2] => 4854885.jpg)`
phpExe
Isn't that you are looking for?
fabrik
I want somthing like this :Array ( [0] => 9292066.jpg ) Array ([1] => 5713362.jpg ) Array ([2] => 4854885.jpg ).Because I want to save image name in database (I dont know If it is a right way)
phpExe
Im sorry:( In third section of array there is "Array ( [0] => 9292066.jpg [1] => 5713362.jpg [2] => 4854885.jpg"I want Only the [2] => 4854885.jpg section.
phpExe
Sorry, i think i don't understand you. $_FILES['images']['name'] is an array, right? If you loop through these images and store their names in an array, my solution must be fine i think.
fabrik
Thanks for help ;)
phpExe
What was the problem?
fabrik
with your trick and adding the $name1[] = $name;
phpExe