Tracking Forums, Newsgroups, Maling Lists
Home Scripts Tutorials Tracker Forums
 
  HOME    TRACKER    PHP




Deleting All Files With A Certain Prefix


I'm using php 4.4.4. Given a particular directory, I want to delete
all the files that begin with the variable "$prefix". What is the
simplest way to do this?




View Complete Forum Thread with Replies

See Related Forum Messages: Follow the Links Below to View Complete Thread
Deleting All Files
Is it possible to delete all files in a folder using unlink() or something similar?

Deleting Files
The below should delete files from a dir older than a week. I set the $dtime to 0 to test the script but it deletes nothing. What is wrong? Code:

Deleting Files
I'm using different files to store some arrays to make administration of a very small job-logger very easy. I currently read the file, remove the element to be deleted, delete the whole file, and write the file again without that element. Is there a way to remove a single element out of that file without deleting the whole file?

Deleting Files
I'm trying to modify this script to remove files that end with %enlarged.jpg or %enlarged.gif or %enlarged.png, can someone help with the if statement, I've tried several things, of which, nothing is working: Code:

Deleting Files
I have some script that takes an album id and deletes that album and the specific photos in that album. The code does run. The problem is that an error message i set to echo appears saying error deleting photo once the page automatically refreshes. When i check the image folder the images actually have been deleted. Code:

Deleting Files From A Folder...
I have a folder with many pictures in it.
All have the name like: HHMMDDMMYYYY.jpg

H-hour
M-minute
D-day
M-month
Y-year

Now I want to delete all pictures which are older than now()-7days.
How Can I do it? In SQL would be no prob but with file deleting is problem.

Deleting All The Files In A Directory
Using PHP 4, what are the shortest amount of lines I can write to
delete all the files in a given directory?

Deleting Files From A Server
As part of a project I want to allow users to save files to a server or delete files from a server. I have the uploader working fine, but i have no idea how i would delete the file from the server.

Attaching/deleting Files
I'm trying to create a tree where you can access files from the tree. The files will NOT be stored in the database, but on the server. I have a web forum eg, where they store the title of the message in a separate table compared with the message which is another table.

How do I store the files and show them on the tree, and how will the system know where to get the files from, if they're not in the database?

Deleting Files Onclick
I have an app that lists out the files on a server.  I have a checkbox at the end of each file.  You can check any number of files.  Then I have a link at the top that says "delete selected files."  Could someone just tell me how to write the code to delete the files in general?  I'm not asking for all the exact code, just the concept.  I assume I will be calling a php or javascript function with the "onclick" method. Code:

Creating And Deleting Folders And Files
Hi to Everyone.

After creating trought http a organize number of files and folders. I'm not able to delete them, not even trought an FTP Software like Cute FTP. It replies "Could not delete xxxxx.html".

Error Deleting Uploaded Files
I have a configuration script which creates a directory on the server, directory used for uploading files. Everything works fine (creation of the directory, uploading) but when I try to delete an uploaded file from this directory using total commander as ftp client I get the following error: "550 Delete operation failed".

The used code is something like this:

$cursuri = "../cursuri";
@mkdir($cursuri, 0777);

Note: if I use total commander "chmod 777 cursuri" I don't get any problems.

Deleting Files In A Folder Modified Before Certain Date
I use a cache system that requires creation of files in a folder .

Now , what i need to know is how can i delete files created say 3 days ago.

So that the cache remains fresh.

The directory contains around 20,000 files , about 10,000 are generated each day (if they dont exist)

So getting info about the each file after using opendir will cause the server to slow down.

Zend Studio 3.5.2 Possibly Deleting Files?
At work I'm using Zend Studio 3.5.2 to develop PHP files on my Win2K
desktop machine. I've got Zend Studio setup with a secure FTP (SFTP)
connection to a RedHat Enterprise Linux machine. The files I'm editing
'live' on a Solaris machine and the linux machine mounts them through
NFS. I actually access the files through a symbolic link to the mount
point on the linux box. A little complicated I know, but it does work.

I've been having a random problem lately. Every once in awhile (every
couple of weeks) when I'm in Zend Studio and have a few (not all) php
files open, all the files in the directory where I'm working get
corrupted. They all get turned to a file of nothing but nulls (zeros)
and the files are exactly 512 bytes long. This concerns me because it
seems to only happen to me even though other people work on PHP files
in other directories. The difference is that I'm the only one who uses
Zend Studio regularly. I can't see how that would be a problem since
the connection to the files is through SFTP and is essentially
stateless and connectionless. Has anyone else seen this problem or have
any insight about what might be going on?

Editing And Deleting Flat Text Files
I am working on a php news script that uses text files for it's DB. I have most of it done except for the ability to edit or delete the articles in the DB.

I have only been coding for about a week now so my skills are pretty limited and I have not found any tutorials that cover this issue so if anyone could be kind enough as to show me how this is done I would be most greatful....

Prefix A File Upload
I am unusre of the correct syntax for prefixing the following so it includes the category from another field.

I need the following:
 if(empty($_FILES['file_name']['name'])) 

 $file_name = $old_file_name; 

 else 

 $file_name = $_FILES['file_name']['name']; 

To be able to have the category value in the file name at the start, so prefixing the actual image file name.

How To Trim Parameters And Give Them A Prefix?
// trim the parameters
foreach($_POST as $varname =$value) {$varname = trim($value);}

// give them $p_ prefix
import_request_variables('gp', 'p_');

When I do the above the parameters are not trimmed in the end.

Example:

$lastname = ' ' is trimmed to $lastname = '', but $p_lastname = ' '

Adding A Prefix To An Autogenerated Number
I need to add a prefix letter to sequential numbers that are autogenerated (a bit like creating invoice numbers) the guilty party is called accom_id this knocks out a 5 digit number which now needs to be displayed in the end result -either as a client page or data entry- as 'e12345' as opposed to '12345' - Code:

How I Can Find Longest Common Prefix Of Strings
I'm interested in such algorithm that solves problem of finding longest
common prefix of two or more strings.

I haven't found such function in PHP, or I pass it?

Deleting Files Using Unlink [function.unlink]: Permission Denied
I have a record in the db and a picture file name recorded with that record. I am writing a deletion routine which checks that file name and is supposed to delete it using unlink.

Although it reports the correct directory and file name, I received the following:

Warning: unlink(/home/pab/html/pics/test.jpg) [function.unlink]: Permission denied

I checked my permissions and the file is set at my user name and 666.

Does anyone know why this won't work or maybe another way to delete the file?

Batch File Deleting And Folder Deleting
I have a folder in my web site where I used php to create and copy in files. but now I can't delete them easily. The only way I know how that is possible is through php. I get an error the following ftp error:

550 th: Permission denied
I had the chmod() set to 0777 on every file and folder. But I still seem to loss control over the files when I try and do things with them through other means.

I think it is because the user I use to access the files via ftp a diffrent user. So I tryed to add a function with chown() for the new files I was posting and uploading. It didn't work on those new files. so it looks like the only thing I can do is use the unlink() function which deletes the files fine.

The only problem is now I have something like 100 sub directories all with files in them. I need to figure out a way to batch delete them. I can't find a script that goes through and finds all file contents including all sub directories and unlink those things.

I found some that will use a for loop to list out the contents of a folder but it is just files. No sub directories. Any body got any ideas on which functions I should use or know where a script is that I can base mine off of.

I am not sure how to approach this since what I tryed with chown and chmod has failed thus far. I currently have no code and am starting from scratch on this batch flushing of my directory.

How Do You Pass A Variable Via A "pseudo-directory" Or URL Prefix?
I've searched everywhere for this but I'm not sure exactly what to
search for.

What I am trying to do is pass a variable to a php script via the URL.
However, I don't want to use the standard "?name=value format." I want
to either pass the variable as "value website.com" or
"website.com/value" where the script is stored in some directory
"website.com/script/index.php" and the value gets stored in a variable
declared within my php script.

I have seen this done but I just need some guidance on how to go about
doing it.

Deleting
how could i delete everything from a table in a mysql db except for the 10 latest things ?

Deleting The Saved Db The One Before?
I made a script that backups the database as sql file in the server. I mean script writes it into the harddrive, but everytime when i execute the script the harddrive loss another 3 mb. How can i modify the script to delete the one before when i execute it to write the new one?

Need Help With Deleting Records
I'm trying to add a link on the display of a record to delete that record.

The main part of the record is stored in pw_event, then there are several rating fields for that record stored in pw_rate, and there is also several records for the first record stored in pw_whois.

I need to have a link that will deleted everything for that record in all three tables.

Here is my display script:

PHP Code:

Deleting Last Comma
The code below displays pet names like so:

Fido, Bowser, Kittycat, Spot,

and I want to delete only the last comma. I tried 'substr' and 'rtrim' and both of those delete the space and comma between each name, not just the last name as I'd like, so I end up with:
Fido,Bowser,Kittycat,Spot,

How would I delete only the last comma, so that it is this instead?
Fido, Bowser, Kittycat, Spot

Even with trim and substr, I end up with:

Deleting A Session
I want to be able to delete a session so that the next time there's a call to session_start, it creates a new session ID. I don't want to destroy the session variables specifically (though this will be a side-effect of what I'm doing) so I know that session_destroy isn't what I want to do.

I presume I should just delete the session cookie manually. Is there a neater way? And if not, how do I do this?

Deleting A Director
I'm using this code trying to make ato delete a file or folder under w2k, apache.

$direct=split("repadmin.php",$PATH_TRANSLATED);
$file=$direct[0].$filedeleted;
$filesys = eregi_replace("/","",$file);
$delete = @chmod ($filesys, 0775);
unlink("$delete");
header("Location:repadmin.php");
exit;

but return this warning:

Warning: unlink(1) [function.unlink]: No such file or directory in c:program filesapache groupapachehtdocsguonline epositorio epadmin.php on line 94

I checked the whole path and looks good.

Deleting Cookies?
For some reason is i set my cookies like this PHP Code:

Deleting A Line
how do i delete from a text file 1 of the following lines

jon|scott
adam|smith <--delete
paul|clark

say i would like to delete the middle line of this txt, in member.txt
what php code or logic would help me accomplish this?

Also i am clicking on a hyperlink that is keeping count of the entries
i have
made. e.g php?record_id =1
php?record_id =2

Deleting A Record.
One last (hopefullly) problem I can't seem to get around for this
program...why isn't this deleting the row i want? It does nothing. Now error
messages either. HELP!

$link = mysql_connect("localhost");
if(! $link)
die("Could not connect to MySQL");

$database = "PC_Store";
mysql_select_db($database)
or die ("could not open $database: ".mysql_error() );

$result = mysql_query("DELETE FROM inventorydata VALUES('$ProductID')");

The $ProductID variable is brought in from a menu choice on a diffrent page,
it is also the primary of the table...so it should delete the whole row
right?

Deleting Records
I've been trying to delete records since a week and i'm not able to do it. Before with this script, i was doing so many things at a time and i was confused.But, now, i just displaying the records from a table N trying to delete them.Would somebody pls guide me.

I just wanna set the delete flag(i.e, i want to set the RBS_DELETE column to Y or something) when i check a check box to delete it. I've some 5 records displaying on my form and i want to check 3 of them and when i check them and hit submit, i want the RBS_DELETE column to have some value. PHP Code:

Deleting A Row From A Database
I can't fiqure out why my delete function isn't working. I have a listing of rows in my database with an option to delete an individual row at the end: Code:

Deleting A Message
I want a button to delete each message in you inbox wen clicked. im using this that doesn't work, because i coded it Code:

Cookie Not Deleting
login.php:
setcookie('id', $userinfo['id'], time()+60*60*24*31*3 , '/');

logout.php:
setcookie('id', '', time()-60*60*24*2);

Any idea why it is not deleting my cookie?

Deleting Posts
How can I delete my previous post?  It's showing up in Google when I search for the url referenced in my previous post (if I put the name here, it will show this post, too).  If I can't delete it, can I make it so that Google can't pick it up?

Deleting Folder
is there anyway of deleteing a folder and deleting all of its contents with it?
i know that with rm_dir needs to folder to be emptied

Deleting The Pages!!!
I wanted the php files in my computer to be protected.If someone copies them and use in different machines,how can the php code find that the code is running in nextmachine. Is there any idea,that I delete the files using the unlink() method,when they are stored/run in next machine.

Deleting Using Checkboxes
im wanting to delete multiple things from a database using checkboxes, now i know how to use checkboxes in php etc. my question is would this be done using a basic while loop? i mean would i query all the things and then do

while ($check_box == 'ON')
{
do the delete script
}

or is there something more to it?

Deleting A Line From.txt
it writes the line or lines to be deleted correctly into issues_deleted.txt which is line fwrite($file_contents_deleted, $value);

and when it refreshes the line still exists in banip.txt it does echo out the line as well just doesnt remove it from banip.txt anyone know why? Code:

Deleting From Sql Database
I have used this script I made to delete files from a server and simultaneously remove information about the file from a database. I have uploaded the same script to a new website and it no longer works. The file does get deleted but the database line doesn't get removed. I can tell where it's going wrong by the error custom error message 'echo'ed on the page ("your file was only partially uploaded"), but I really don't know why.

Deleting Elements From Arrays
I'm trying to delete empty elements (elements that contain empty strings) from the array with unset() function by looping through the array.

Deleting An Element In An Array??
Here is the problem:

I've got an array with the following elements

$array = ("ice","ice","polka","skate","polka");

thats 2 polka, 2 ice and 1 skate

Now i want someway of removing just one of the polka's from it..

so that i'd be left with:
$array = ("ice","ice","skate","polka");

what i did was a basic search with for loop and break

Code: for($x=0;$x<sizeof($array);$x++)
{
if($array[$x] == "polka")
{
echo("match ".$x);
break;
}
} alls well n good till now.. now i've got the index value(2 in this case) of the element which needs to be deleted.. but what should be done now?? is there any function which'll let me delete a particular element in an array?

Is there any other way to go around this?

Deleting Contents In File With PHP
Hi, I need to get to a specific part of the file and delete a line so i can overwrite it with a new value. Example ...

$Money = array(
0 => 10000,
1 => 932394,
2 => 3254#<Money>
);

I need to change first choice "0 => 10000" and replace it with "0 => 7500" so it seems like they spent 2500 moneys I dunno if its possible but if it is please help, and thanks in advance FYI, the file is called testfile.inc and i dunno what that .inc means :P I just got it from a script i downloaded Further more, i want to do this change/replace through a form or a click using PHP.

Deleting Uploaded File
I am using a from in which users enter data as well as upload a file. I also give them an opportunity to delete their entry. Currently I am deleting the entry from the database.

Deleting Characters In A String?
I looked in the PHP manual and could not find a function to remove characters from a string. Anyone know how?

The reason I want to do this is because I need a date retrieved from mySQL to show as follows:

2001.01.01 = January 1, 2001

and the only way I currently know how is to use a function to transform the month returned from mySQL into the month name. However, it will not work corectly because it is an array function and 01 does not equate to 1 in an array apparently. Someone mention to me that there was a function that does this. Can someone tell me what that one is?

Problems Deleting A Cookie
I'm having great difficulty deleting a cookie in a script of mine. I have searched around the forum, but the solutions offered for deleting a cookie didn't do it for me. The point of the script is to automatically log users in when they visit the index page of the site. I set the cookie as follows in the login script:

Deleting Rows In Mysql
Is there a way in php that I can mark a row in my mysql database and then later so delete these rows that have been marked?

Deleting An Element From An Array
I'm not being an idiot here and missing something very obvious as I seem to be prone to doing.

I have the following code:


Copyright © 2005-08 www.BigResource.com, All rights reserved