[advanced search]
 

Go Back   NamePros.com > Discussion > Web Design & Development > Programming

Programming PHP, Perl, Ruby on Rails, AJAX, HTML, XHTML, CSS, JavaScript, MySQL and any other coding topics.


Closed Thread
 
LinkBack Thread Tools
Old 07-01-2006, 02:45 PM   #1 (permalink)
Account Closed
 
Join Date: Oct 2005
Location: United Kingdom
Posts: 1,554
55.39 NP$ (Donate)

NetworkTown.Net is just really niceNetworkTown.Net is just really niceNetworkTown.Net is just really niceNetworkTown.Net is just really nice


Deleting Files

Hi

I have made a image host script i want to make a admincp now so in the admincp i need help i want to know how i can do this:

List all images in the directory (in a 250 * 200 box or something in a list)
Then at the side of the images put a link so i can delte a image, i know it would use unlink or something but i can't figure out how to do it, iv got this so far;

PHP Code:
<?
$read
= '../DirPathNameHere/';    
$myDirectory = opendir($read);    
   while(
$entryName = readdir($myDirectory))
   {
      if (
strtolower(substr($entryName, -3)) == "jpg")
      {
         
$dirArray[]=$entryName;
         echo
$entryName.'<br />';

         echo
'<TABLE width=500 align=center BGCOLOR=#CCCCCC>';
            echo
'<TR><TD align=center valign=center>';
               echo
'<img src=' .$read.$entryName. '><BR>';
            echo
'</TD></TR>';
         echo
'</TABLE>';
       }
   }
   
closedir($myDirectory);
?>
And also i had this from sitepoint but did not understand any one: http://www.sitepoint.com/forums/showthread.php?t=367792


Thanks.
NetworkTown.Net is offline  
Old 07-01-2006, 04:12 PM   #2 (permalink)
Senior Member
 
Peter's Avatar
 
Join Date: Nov 2003
Location: Scotland
Posts: 4,900
0.60 NP$ (Donate)

Peter has a reputation beyond reputePeter has a reputation beyond reputePeter has a reputation beyond reputePeter has a reputation beyond reputePeter has a reputation beyond reputePeter has a reputation beyond reputePeter has a reputation beyond reputePeter has a reputation beyond reputePeter has a reputation beyond reputePeter has a reputation beyond reputePeter has a reputation beyond repute

Child Abuse Save The Children Save The Children Help The Homeless - Holiday 2009 Help The Homeless - Holiday 2009 Help The Homeless - Holiday 2009 Help The Homeless - Holiday 2009
something like the following should be ok:-

PHP Code:
<?
$read
= '../DirPathNameHere/';
if (isset(
$_GET['delete']) && !empty($_GET['delete']) && is_file($read.$_GET['delete']) && ereg("^[[:alnum:]]+$",$_GET['delete']))
{
    
unlink($read.$_GET['delete']);
}    
$myDirectory = opendir($read);    
   while(
$entryName = readdir($myDirectory))
   {
      if (
strtolower(substr($entryName, -3)) == "jpg")
      {
         
$dirArray[]=$entryName;
         echo
$entryName.'<br />';

         echo
'<TABLE width=500 align=center BGCOLOR=#CCCCCC>';
            echo
'<TR><TD align=center valign=center>';
               echo
'<img src=' .$read.$entryName. '><BR></TD>';
            echo
'<TR><TD align=center valign=center><a hregf="'.$_SERVER['PHP_SELF'].'?delete'.$entryName.'">Delete image</a></TD></TR>';
         echo
'</TABLE>';
       }
   }
   
closedir($myDirectory);
?>
I have not checked the script but it shows you basically what needs to be done. Also just a note it would be better if $read was an absolute server path to the necessary folder instead of relatie to the current location.

Last edited by filth@flexiwebhost; 07-01-2006 at 04:17 PM.
Peter is offline  
Old 07-01-2006, 04:19 PM   #3 (permalink)
Account Closed
 
Join Date: Oct 2005
Location: United Kingdom
Posts: 1,554
55.39 NP$ (Donate)

NetworkTown.Net is just really niceNetworkTown.Net is just really niceNetworkTown.Net is just really niceNetworkTown.Net is just really nice


I just get a ablank page with that.
NetworkTown.Net is offline  
Old 07-01-2006, 08:26 PM   #4 (permalink)
NamePros Regular
 
Join Date: Dec 2005
Posts: 206
270.00 NP$ (Donate)

wackyjoe is on a distinguished road


Quote:
Originally Posted by NetworkTown.Net
I just get a ablank page with that.
PHP Code:
  <?
$read
= '../DirPathNameHere/';
if (isset(
$_GET['delete']) && !empty($_GET['delete']) && is_file($read.$_GET['delete']) && ereg("^[[:alnum:]]+$",$_GET['delete']))
{
   
$handle = opendir($read);
   while(
$file=readdir($handle))
   @
unlink($read.$_GET['delete']);
   
closedir($handle);

echo
"<br>Files Deleted";

    
}    
$myDirectory = opendir($read);    
   while(
$entryName = readdir($myDirectory))
   {
      if (
strtolower(substr($entryName, -3)) == "jpg")
      {
         
$dirArray[]=$entryName;
         echo
$entryName.'<br />';

         echo
'<TABLE width=500 align=center BGCOLOR=#CCCCCC>';
            echo
'<TR><TD align=center valign=center>';
               echo
'<img src=' .$read.$entryName. '><BR></TD>';
            echo
'<TR><TD align=center valign=center><a hregf="'.$_SERVER['PHP_SELF'].'?delete'.$entryName.'">Delete image</a></TD></TR>';
         echo
'</TABLE>';
       }
   }
   
closedir($myDirectory);
?>
wackyjoe is offline  
Old 07-01-2006, 10:14 PM   #5 (permalink)
Senior Member
 
Peter's Avatar
 
Join Date: Nov 2003
Location: Scotland
Posts: 4,900
0.60 NP$ (Donate)

Peter has a reputation beyond reputePeter has a reputation beyond reputePeter has a reputation beyond reputePeter has a reputation beyond reputePeter has a reputation beyond reputePeter has a reputation beyond reputePeter has a reputation beyond reputePeter has a reputation beyond reputePeter has a reputation beyond reputePeter has a reputation beyond reputePeter has a reputation beyond repute

Child Abuse Save The Children Save The Children Help The Homeless - Holiday 2009 Help The Homeless - Holiday 2009 Help The Homeless - Holiday 2009 Help The Homeless - Holiday 2009
wackyjoe there is no reason to open the directory like you do to delete a file.
Peter is offline  
Old 07-02-2006, 02:38 AM   #6 (permalink)
Account Closed
 
Join Date: Oct 2005
Location: United Kingdom
Posts: 1,554
55.39 NP$ (Donate)

NetworkTown.Net is just really niceNetworkTown.Net is just really niceNetworkTown.Net is just really niceNetworkTown.Net is just really nice


Quote:
Originally Posted by wackyjoe
PHP Code:
  <?
$read
= '../DirPathNameHere/';
if (isset(
$_GET['delete']) && !empty($_GET['delete']) && is_file($read.$_GET['delete']) && ereg("^[[:alnum:]]+$",$_GET['delete']))
{
   
$handle = opendir($read);
   while(
$file=readdir($handle))
   @
unlink($read.$_GET['delete']);
   
closedir($handle);

echo
"<br>Files Deleted";

    
}    
$myDirectory = opendir($read);    
   while(
$entryName = readdir($myDirectory))
   {
      if (
strtolower(substr($entryName, -3)) == "jpg")
      {
         
$dirArray[]=$entryName;
         echo
$entryName.'<br />';

         echo
'<TABLE width=500 align=center BGCOLOR=#CCCCCC>';
            echo
'<TR><TD align=center valign=center>';
               echo
'<img src=' .$read.$entryName. '><BR></TD>';
            echo
'<TR><TD align=center valign=center><a hregf="'.$_SERVER['PHP_SELF'].'?delete'.$entryName.'">Delete image</a></TD></TR>';
         echo
'</TABLE>';
       }
   }
   
closedir($myDirectory);
?>
that dose not work either.
NetworkTown.Net is offline  
Old 07-02-2006, 06:26 AM   #7 (permalink)
Pro Coder & Designer
 
xlusive's Avatar
 
Join Date: Apr 2005
Location: Netherlands
Posts: 964
101.50 NP$ (Donate)

xlusive is just really nicexlusive is just really nicexlusive is just really nicexlusive is just really nicexlusive is just really nice


Are permissions set correctly ?
__________________
Online Dragonball Game
xlusive is offline  
Old 07-02-2006, 07:50 AM   #8 (permalink)
Account Closed
 
Join Date: Oct 2005
Location: United Kingdom
Posts: 1,554
55.39 NP$ (Donate)

NetworkTown.Net is just really niceNetworkTown.Net is just really niceNetworkTown.Net is just really niceNetworkTown.Net is just really nice


Yep they are, they are set to 777
NetworkTown.Net is offline  
Old 07-02-2006, 08:48 AM   #9 (permalink)
Senior Member
 
Peter's Avatar
 
Join Date: Nov 2003
Location: Scotland
Posts: 4,900
0.60 NP$ (Donate)

Peter has a reputation beyond reputePeter has a reputation beyond reputePeter has a reputation beyond reputePeter has a reputation beyond reputePeter has a reputation beyond reputePeter has a reputation beyond reputePeter has a reputation beyond reputePeter has a reputation beyond reputePeter has a reputation beyond reputePeter has a reputation beyond reputePeter has a reputation beyond repute

Child Abuse Save The Children Save The Children Help The Homeless - Holiday 2009 Help The Homeless - Holiday 2009 Help The Homeless - Holiday 2009 Help The Homeless - Holiday 2009
have you tried changing $read to a absolute path instead of a relative path.

Also try putting the following line at the top of the file (after the <?php):-

PHP Code:
error_reporting(E_ALL ^ E_NOTICE);
And let me know if you receive any error.
Peter is offline  
Old 07-02-2006, 09:09 AM   #10 (permalink)
Account Closed
 
Join Date: Oct 2005
Location: United Kingdom
Posts: 1,554
55.39 NP$ (Donate)

NetworkTown.Net is just really niceNetworkTown.Net is just really niceNetworkTown.Net is just really niceNetworkTown.Net is just really nice


Still getting blank screen.
NetworkTown.Net is offline  
Old 07-02-2006, 09:27 AM   #11 (permalink)
Senior Member
 
Peter's Avatar
 
Join Date: Nov 2003
Location: Scotland
Posts: 4,900
0.60 NP$ (Donate)

Peter has a reputation beyond reputePeter has a reputation beyond reputePeter has a reputation beyond reputePeter has a reputation beyond reputePeter has a reputation beyond reputePeter has a reputation beyond reputePeter has a reputation beyond reputePeter has a reputation beyond reputePeter has a reputation beyond reputePeter has a reputation beyond reputePeter has a reputation beyond repute

Child Abuse Save The Children Save The Children Help The Homeless - Holiday 2009 Help The Homeless - Holiday 2009 Help The Homeless - Holiday 2009 Help The Homeless - Holiday 2009
were you getting a blank screen before you made these changes?

Nothing about these changes should cause no output, can you double check by looking at the source when you go to the page.
Peter is offline  
Old 07-02-2006, 09:56 AM   #12 (permalink)
Account Closed
 
Join Date: Oct 2005
Location: United Kingdom
Posts: 1,554
55.39 NP$ (Donate)

NetworkTown.Net is just really niceNetworkTown.Net is just really niceNetworkTown.Net is just really niceNetworkTown.Net is just really nice


Quote:
Originally Posted by filth@flexiwebhost
were you getting a blank screen before you made these changes?

Nothing about these changes should cause no output, can you double check by looking at the source when you go to the page.
Well i found that code on sitepoint so i dont know but i just got it to start me off and help you/other to help me.
NetworkTown.Net is offline  
Old 07-02-2006, 01:34 PM   #13 (permalink)
NPQ's PA, Slave, and On Call Coder

Technical Services


 
Eric's Avatar
 
Join Date: Mar 2005
Posts: 4,545
0.71 NP$ (Donate)

Eric has a reputation beyond reputeEric has a reputation beyond reputeEric has a reputation beyond reputeEric has a reputation beyond reputeEric has a reputation beyond reputeEric has a reputation beyond reputeEric has a reputation beyond reputeEric has a reputation beyond reputeEric has a reputation beyond reputeEric has a reputation beyond reputeEric has a reputation beyond repute

Save a Life Child Abuse 9/11/01 :: Never Forget Baby Health Marrow Donor Program AIDS/HIV Breast Cancer Cystic Fibrosis Ethan Allen Fund Animal Cruelty Ethan Allen Fund Ethan Allen Fund Cancer Alzheimer's Protect Our Planet Cancer Survivorship SIDS Child Abuse
Edited a bit.

I tried this and I know it works:
PHP Code:
<?php

$read
= 'images/';


if (!empty(
$_GET['delete']) AND file_exists($read . $_GET['delete']))
{
    if (
unlink($read . $_GET['delete']))
    {
        echo
'File deleted.<br /><br />';
    }
    else
    {
        echo
'File could not be deleted.<br /><br />';
    }
}

if (
$myDirectory = opendir($read))
{
    while (
false !== ($entryName = readdir($myDirectory)))
    {
        if (
strtolower(substr($entryName, -3)) == "jpg" OR strtolower(substr($entryName, -3)) == 'gif')
        {
            
$dirArray[] = $entryName;
            echo
$entryName . '<br />';
            echo
'<TABLE width=500 align=center BGCOLOR=#CCCCCC>';
            echo
'<TR><TD align=center valign=center>';
            echo
'<img src=' . $read . $entryName . '><BR></TD>';
            echo
'<TR><TD align=center valign=center><a href="' . $_SERVER['PHP_SELF'] . '?delete=' . $entryName . '">Delete image</a></TD></TR>';
            echo
'</TABLE>';
        }
    }
    
closedir($myDirectory);
}

?>
__________________

Last edited by SecondVersion; 07-02-2006 at 01:40 PM.
Eric is offline  
Old 07-02-2006, 02:20 PM   #14 (permalink)
Account Closed
 
Join Date: Oct 2005
Location: United Kingdom
Posts: 1,554
55.39 NP$ (Donate)

NetworkTown.Net is just really niceNetworkTown.Net is just really niceNetworkTown.Net is just really niceNetworkTown.Net is just really nice


SV still getting a blank page, here i found another script that dont give me a blank page,

PHP Code:
<?

function deldir($dir) {
    
$dh=opendir($dir);
        while (
$file=readdir($dh)) {
            if(
$file!="." && $file!="..") {
            
$fullpath=$dir."/".$file;
            if(!
is_dir($fullpath)) {
                
unlink($fullpath);
            } else {
                
deldir($fullpath);
            }
        }
    }
    
closedir($dh);
    
    if(
rmdir($dir)) {
        return
true;
    } else {
        return
false;
    }
}

if(!empty(
$_POST['delete'])) {
    foreach(
$_POST['delete'] as $todel) {
        echo
'Deleting File: '.$todel.'<br />';
        
deldir($todel); // Function call to deldir.
    
}
    echo
'<br />';
}
//change the below to the full path to the folder
//requires the trailing /
$folderpath = '/home/networkt/public_html/imgscript/';
$filelist = glob($folderpath.'*');
if(!
is_readable($folderpath)){
  die(
'Invalid folderpath: '.$folderpath);
}

echo
"<form method='post' action=''>";

if(empty(
$filelist)) {
    echo
'No files found.<br />';
    } else {
        foreach(
$filelist as $file){
        echo
$file.'&nbsp;<input type="checkbox" name="delete[]" value="'.$file.'" /><br />'."\n";
    }
}

?>

<input type="submit" name="submit" value="submit" />
</form>
I get this error when trying to delte something: Warning: rmdir(/home/networkt/public_html/imgscript/view): Permission denied in /home/networkt/public_html/imgscript/admincp.php on line 17

I set the files/folder to 777
NetworkTown.Net is offline  
Closed Thread


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not 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


Site Sponsors
Advertise your business at NamePros

All times are GMT -7. The time now is 02:28 AM.


Powered by: vBulletin® Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.3.0
Template-Modifications by TMS
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85