John Davidson

php - Using glob with comma in path folder

0 comments
Message:


I'm using glob function to get the contents of a folder. It's working fine but when the folder name looks like this Test, Folder it doesn't work and returns an empty array.


My code:


$path = 'upload/Test, Folder';
print_r(glob(ABSPATH.$path."/*.*"));


My Answer:
'/*'));_

The issue here is that the comma in the folder name is causing glob to interpret it as two separate paths. To fix this, you can use the glob function with the GLOB_BRACE flag to handle the comma in the folder name.

Here's an updated version of your code:

php
$path = 'upload/Test, Folder';
print_r(glob(ABSPATH . '{' . $path . '}/*', GLOB_BRACE));


By using the GLOB_BRACE flag and enclosing the path in curly braces, glob will treat the entire path as a single entity and correctly retrieve the contents of the folder.

Rate this post

5 of 5 based on 2123 votes

Comments




© 2024 Hayatsk.info - Personal Blogs Platform. All Rights Reserved.
Create blog  |  Privacy Policy  |  Terms & Conditions  |  Contact Us