Jump to content
mrravee

can someone help me with this php code?

Recommended Posts

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. I have my code here I was told that I have to do something with an array, but I can't figure it out can someone help me?

 

?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);
}

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

 

Share this post


Link to post
Share on other sites

Use glob() function which returns an array of the files.

E.G.

    $folder = 'C:/Users/... /chartSamples/' ;
    foreach (glob("{$folder}*.png") as $fn) {
        echo basename($fn) . '<br>';
    } 

giving

column.png
doughnut.png
line.png
radar.png
rosechart.png
stacked.png

 

  • Like 1

Share this post


Link to post
Share on other sites

One more question

I put my code in $ files because this code had to be in the array so that you can see which picture is in the folders after the upload.

code:

$ destination. “/”. $ _FILES [‘file’] [‘name’] [$ i];

now I have a problem the $i with $files does not work because I have not linked it yet in the code below I have no idea how to do this I heard something with element in aray

can anyone help me?

the full 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 = $destination . ‘/’ . $_FILES[‘file’][‘name’][$i];

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

 

Share this post


Link to post
Share on other sites
3 hours ago, mrravee said:

One more question

I put my code in $ files because this code had to be in the array so that you can see which picture is in the folders after the upload.

code:


$ destination. “/”. $ _FILES [‘file’] [‘name’] [$ i];

now I have a problem the $i with $files does not work because I have not linked it yet in the code below I have no idea how to do this I heard something with element in aray

can anyone help me?

the full 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 = $destination . ‘/’ . $_FILES[‘file’][‘name’][$i];

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

got it 

 

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


×
×
  • Create New...

Important Information

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.