mrravee Posted September 30, 2019 Share Posted September 30, 2019 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] ); } Quote Link to comment https://forums.phpfreaks.com/topic/309299-can-someone-help-me-with-this-php-code/ Share on other sites More sharing options...
Barand Posted September 30, 2019 Share Posted September 30, 2019 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 1 Quote Link to comment https://forums.phpfreaks.com/topic/309299-can-someone-help-me-with-this-php-code/#findComment-1570071 Share on other sites More sharing options...
mrravee Posted October 2, 2019 Author Share Posted October 2, 2019 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] ); } Quote Link to comment https://forums.phpfreaks.com/topic/309299-can-someone-help-me-with-this-php-code/#findComment-1570212 Share on other sites More sharing options...
mrravee Posted October 2, 2019 Author Share Posted October 2, 2019 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 Quote Link to comment https://forums.phpfreaks.com/topic/309299-can-someone-help-me-with-this-php-code/#findComment-1570216 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.