Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 4 years ago.
Improve this question
I have saved images in a file in the storage. I would like to get the files saved into an array using exec command in the controller and then pass the array into the blade. Is there any way to do it?
$images= [];
// $filesInFolder = \File::files('images'); getting files from the folder
$files = file_get_contents( 'filename' ); // replace here the filename with you full path of the file
foreach($files as $path)
{
$images[] = pathinfo($path);
}
Then you can pass the images/files in your blade.
Related
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 2 years ago.
Improve this question
I am new to PHP, FTP connection.
I have to check a folder on a remote location ( ftp location ) that whether this folder exist or not.
I have tried through curl but it is not showing correct result.
maybe it would be easier to use an FTP PHP library , try this one php-ftp-library
try to use this code:
<?php
$path = 'your file name';
if (!is_dir($path)) {
//do something
} else {
//do something else
}
?>
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 6 years ago.
Improve this question
How can I delete all files with a PHP script on a server? My problem is that I have many files that need to be deleted and over the FTP client it takes quite a long time.
you can delete all files using for loop, example:
`
$files = glob('path/to/temp/*'); // get all file names
foreach($files as $file){ // iterate files
if(is_file($file))
unlink($file); // delete file
}
`
Untested but this should work:
$dir = "dir/to/purge/"; // Directory you want to remove all the files from
$listing = scandir($dir); // Array containing all files and directories inside the provided directory
foreach($listing as $file) {
if(is_file($dir . $file)) {
unlink($dir . $file); // Removes the file from the listing
}
}
Note that with a lot of files this could use up all your memory.
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
I have stumbled upon a problem while developing a simple website. I wanted to know how could I access and display all images stored in a folder inside another folder ?
Thanks for the input! =)
you could use scandir() function to read all files in a folder then filter that files and get only images from theme
<?php
$folder = 'images';
$files = scandir($folder);
$types = array('jpg','png','gif');
foreach($files as $file) {
$exp = explode('.', $file);
$ex = end($exp);
if(in_array($ex , $types)) {
echo '<img src="'. $folder .'/'.$file.'" />';
}
}
?>
or use glob() to read only images in a dir the line of code below gets all .jpg images
$files = glob("images/*.jpg");
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 9 years ago.
Improve this question
I have a folder in my website, is it possible to check if a file exist for comparing with a data query ?
I mean if $donnees["DATA"] == one of the files of the folder.
I don't know any function or something about that.
For instance if Data = 25478
In my folder :
Differents name of file :
24788
24777
25478
$listOfFiles = glob("*");
if(in_array($donnees["DATA"], $listOfFiles) {
//do stuff
}}
You can use glob("*.txt") for .txt files etc etc.
Yes, you can use glob function:
//path to directory to scan
$directory = "somefolder/";
//get all folders/files in specified directory
$files = glob($directory . "*");
//get ach directory/file name
foreach($files as $file)
{
if($donnees["DATA"]==$file){
//do something
}
}
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 9 years ago.
Improve this question
You are right some people are really blind and dumb.
I think that your problem is the file permission.
You must change the file permissions of your images (0644 or 0777 in your chase).
Please read this: http://php.net/manual/en/function.chmod.php.
You can delete images in PHP using the unlink() function.
unlink('path/to/file.jpg');
See http://php.net/manual/en/function.unlink.php .
EDIT:
ALSO you can try this:
if(is_writable($filename))
{
unlink($filename)
} else {
echo 'At this moment this file can't be deleted';
chmod(" YOUR PATH OF $filename", 0777);
unlink($filename);
}
AND
if (file_exists('YOUR PATH OF $filename')) {
echo 'File exist... Sorrrrrrrrrry!!!!!!!!!!!!';
}