LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   Using wildcards with PHP file functions (https://www.linuxquestions.org/questions/programming-9/using-wildcards-with-php-file-functions-148375/)

patpawlowski 02-20-2004 08:40 AM

Using wildcards with PHP file functions
 
I am assuming that you cannot use wildcards # or * with the PHP unlink function. I need a way to delete the pictures off of our web page when we delete a product. All the products pictures are located in the same directory and begin with p_'product number'.... I tried the command unlink(p_'product number'*) but the files weren't deleted. I checked the php manual and they don't mention wildcards. I thougt I could write a function to scan the directory and produce a list of files to unlink but this still would reqire the use of a wildcard.

Any ideas?

Mohsen 02-20-2004 09:53 AM

I dont know if your pictures are named
Code:

p_'product number'*
or
Code:

p_*
.
Assuming the second:
you can concat p_ to product number using dot (.) operator. For example
PHP Code:

unlink ("p_".$pNum); 

where pNum contains the product number.

If this doesn't help, take a look at ereg() manual.

PSIplus 02-20-2004 09:57 AM

Wildcards are interpreted by the shell, so there are two easy solutions:
Don't use them. PHP-Functions don't interprete them.
use opendir & co to scan thru a directory and use unlink

or

do it the nice way:
system("rm whatever");

with exec && system you can execute shell commands :-)

thepi 03-18-2004 09:20 AM

Hi!

Take a look of this

http://pi.nks.com.ar/programacion/unlink_wc.php

Bye!


All times are GMT -5. The time now is 08:49 AM.