GlowHost Web Hosting Forums  

Go Back   GlowHost Web Hosting Forums > In The Lounge > Programming Talk
Register Forum FAQ Search Today's Posts Mark Forums Read

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 08-27-2005
No longer a Newbie
 
Join Date: Apr 2005
Location: Los Angeles Metro
Posts: 5
Rep Power: 0
rickpugh is on a distinguished road
Default PHP Unlink() Function

Hi everyone,

So I could use some newbie advice on using the PHP Unlink() function.

The background info:

I have two different php scripts.
  1. Script "1" allows me to upload files (using file upload) to a given directory that I specify in the configuration.
  2. Script "2" allows me to view (view only) all files that have been uploaded via script 1.
I am currently in the process of modifying Script "2" so that I can delete any file that the user may designate. I am not setting this up to do multiple delte. Just a single file at a time.

I have added the word "delete" to each file detail line. My goal is to set this up so tha when the user "clicks" on the word "delete" on a given file line that file is delted.

The problem:

1. I know that I need to use the PHP Unlink() function to accomplish this task. I know that that the model for this function is basically:

PHP Code:
unlink ($fileToDelete
2. I don't know how to associate this function to the word "delete" and make the function unique to that specified file.

Here is a snippet of my code to help explain what I have done:

Created a delete file function:

PHP Code:
function deletFile (unlink($file)); 
Added a link called "DELETE" to the File "2" (phpDirList) Output

PHP Code:
// Try to get a directory handle and continue if it returns TRUE.
if ($dir = @opendir("./")) {
    
$output ""// Empty the HTML-output variable.
    
while (($file readdir($dir)) !== FALSE) { // Read the directory step by step and process the data.
        
if (test_ext ($file)) { // Check if the entry should be displayed or not and continue if TRUE.
            
$stats = @stat "./".$file); // Get the file stats.
            // And append a table row to the output variable.
            
$output .= '
        <tr class="line">
            <td class="col2">DELETE</td>
            <td class="col1">
                <a title="'
.$file.'" href="'.$file.'">'.$url.''.$file.'</a>
            </td>
            <td class="col2">'
.number_format ($stats[7], 0","".").'</td>
            <td class="col3">'
.str_replace (" "" · "date ("m.d.Y H:i"$stats[9])).'</td>
        </tr>'
."\n";
        }
    } 
    
closedir($dir); // Close the directory handle.
} else {
    
$output "<tr><td colspan=\"3\"><h1>Cannot open Directory!</h1></td></tr>"// Display error message if there was no directory handle returned in the leading condition.

So what's next?

I almost wish I could do something like

HTML Code:
 <a onclick="<?unlink($file)?>">DELETE</a>
Am I going down the right path?

Any help, direction, or comments would be appreciated!
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #2 (permalink)  
Old 01-22-2006
jmarcv's Avatar
immoderate moderator
 
Join Date: Jan 2005
Posts: 297
Rep Power: 67
jmarcv is just really nicejmarcv is just really nicejmarcv is just really nicejmarcv is just really nicejmarcv is just really nice
Default too late?

Rick,

Wow! April 2005, eh? Let me know if you still need help with this!
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may post new threads
You may not post replies
You may not post attachments
You may edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT -5. The time now is 07:56 AM.


Powered by vBulletin® Version 3.7.4
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO
Copyright 2000-2007 GlowHost.com