Need some help with this php code

I had to make a code that automatically creates a folder and in that folder had to come my photo that I was going to upload, That works now. But now I have to make a code that that you can see which photos are in the folder and that has to be done automatically. so have to echo the picture name but automatically

my code:

<?php

ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
error_reporting(E_ALL);

include 'helpers.php';

$foldername = uniqid();
 
$destination = "vierkant/$foldername";

//Check if the directory already exists.
if(!is_dir($destination)){
    //Directory does not exist, so lets create it.
    mkdir($destination, 0755, true);
}

$files = [];

for ($i = 0; $i < count($_FILES['file']['name']); $i++) {
    move_uploaded_file(
        $_FILES['file']['tmp_name'][$i],
        $destination . '/' . $_FILES['file']['name'][$i]
    );

    //
  print_r($_FILES['file']['name']);

}

And what have you tried? Use glob()

https://www.php.net/glob

i’m gonna try this thanks! not sure how it works but i will try

1 Like
$foldername = uniqid();

This is an odd way to do this. It will create a new folder every time it runs. ex,

for($i=0;$i < 20; $i++)
    echo uniqid() . "<br>";

5d91fbbe5a6dc
5d91fbbe5a6e4
5d91fbbe5a6e5
5d91fbbe5a6e6
5d91fbbe5a6e7
5d91fbbe5a6e8
5d91fbbe5a6e9
5d91fbbe5a6ea
5d91fbbe5a6eb
5d91fbbe5a6ec
5d91fbbe5a6ed
5d91fbbe5a6ee
5d91fbbe5a6ef
5d91fbbe5a6f0
5d91fbbe5a6f1
5d91fbbe5a6f2
5d91fbbe5a6f3
5d91fbbe5a6f4
5d91fbbe5a6f5
5d91fbbe5a6f6

i have to make this: can anyone help me with this?

// create a foreach loop that runs over $ upload_files

// and every iteration must run over the function.

// the circles must come in a folder called "circles /your unique name .

ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
error_reporting(E_ALL);

include 'helpers.php';
$foldername = uniqid(); 
$destination = "vierkant/$foldername";

//Check if the directory already exists.
if(!is_dir($destination)){
    //Directory does not exist, so lets create it.
    mkdir($destination, 0755, true);
}

$upload_files =[];

for  ($i = 0; $i < count($_FILES['file']['name']); $i++) {
    move_uploaded_file(
        $_FILES['file']['tmp_name'][$i],
        $destination . '/' . $_FILES['file']['name'][$i]
    );

    $upload_files[] = $destination . '/' . $_FILES['file']['name'][$i];
}

print_r($upload_files);

Not hard

run over what function?

Don’t understand this at all. Is the file name “circles”?

the foreach i dont know how to make it that over runs the upload_files
i have this now

foreach ($upload_files as $loopdata) {
echo $loopdata;

this function: function toCircle the function is in my other code page

and the folder name is circles this function will make picture’s in circle’s so after the function i needs to go to the map circles

Sponsor our Newsletter | Privacy Policy | Terms of Service