/    Sign up×
Community /Pin to ProfileBookmark

[RESOLVED] Problem Deleting a File

I have a web application I am writing. I have decided to use sessions to pass variables that call the action in my switch statements on several different pages. On one of my pages, data from a database table is written to a flat file that is created on the server.

I have an include that calls a function to display any files in my directory that the flat files are written to.

I was going to use the following script to give the user a chance to delete the file from the server from the web page.

Here is the function that I am using…

[code=php]
function output(){
$dir = “converted/”;
//Open a known directory, and proceed to read its contents
if(is_dir($dir)){
if($dh=opendir($dir)){
while(($file=readdir($dh))!==false{
if($file!= ‘..’ && !is_dir($dir.$file)){
$file2=str_replace(” “, “%20”,$file);
$arr=explode(“_”,$file);
$tm=$arr[0];
$arr=explode(“.”,$tm);
$tm=$arr[0];
$tm=date(“h.i.s.A”);
$d=date(“m-j-Y”);
$counter=count($file2);
echo”<br><a href=$dir”.$file2.”>$file</a> | Date: $d <a href=export.php?company=delete&f=$dir”.$file2.”>Delete</a>”;
}
}
closedir($dh)
}
}
}
[/code]

Everything else works accept the delete link…
When they click on the delete it does not change the session variable $_SESSION[‘company’] to “delete”

I need to be able to do this. Can someone either tell me how to do this or tell me a better way to allow a user to delete a file from a directory from the web?

Thanks

to post a comment
PHP

2 Comments(s)

Copy linkTweet thisAlerts:
@ShmohelMay 29.2006 — You don't have quotes around the href. Put single quotes around that part.
Copy linkTweet thisAlerts:
@CbrknightauthorMay 29.2006 — You don't have quotes around the href. Put single quotes around that part.[/QUOTE]

Have checked the quotes. Didnt make a difference with the $_session['company'] variable

I can click the link for the file I created and read it or save it.

So that means the links themselves are working.

There has to be an easier way to delete a file from the server...
×

Success!

Help @Cbrknight spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.25,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...