SitePoint Sponsor

User Tag List

Results 1 to 10 of 10

Thread: Please Help Me

  1. #1
    SitePoint Addict sleepingdanny's Avatar
    Join Date
    Oct 2002
    Location
    Israel
    Posts
    270
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Talking Please Help Me

    Can someone please arrange this code for me so it would be more arranged?? PLEASE

    EDIT: Don't mind the <a href></a> the forum adds it
    PHP Code:
    <?
    include("config.php" );
    $icon=array(
    "[url=http://www.site.net/TypeGIF.gif]http://www.site.net/TypeGIF.gif[/url]",
    "[url=http://www.site.net/TypeJPG.gif]http://www.site.net/TypeJPG.gif[/url]",
    "[url=http://www.site.net/TypeBMP.gif]http://www.site.net/TypeBMP.gif[/url]",
    "[url=http://www.site.net/TypeMIDI.gif]http://www.site.net/TypeMIDI.gif[/url]",
    "[url=http://www.site.net/TypeSWF.gif]http://www.site.net/TypeSWF.gif[/url]",
    );
    $ext=array(".gif",".GIF",".jpg",".JPG",".jpeg",".JPEG",
    ".bmp",".BMP",".mid",".MID",".swf",".SWF"
    );
    if(
    is_dir($dir)){
    [
    email=$fd=@opendir($dir]$fd=@opendir($dir[/email]) or die("Unable To Open The Folder, Please Email The <b>Webmaster</b>." );
    while(([
    email=$part=@readdir($fd))==true]$part=@readdir($fd))==true[/email]){
    if(
    $part!="." && $part!=".." ){
    $file_array[]=$part;}
    }
    if(
    $fd==true){
    closedir($fd);}
    }
    sort($file_array);
    for(
    $i=0$i<count($file_array); $i++){
    $npart=$file_array[$i];
    if(
    strstr($npart,$ext[0])){
    $name=str_replace($ext[0],"",$npart);
    $fsize=filesize($npart);
    $fsize_kb=(int)($fsize/1000);
    $lastchanged=filectime($npart);
    $changeddate=date("d.m.Y",$lastchanged);
    print(
    "<img src=""$icon[0]> <a href=""\"$npart\" target=_blank>$name.gif</a> ---------- " );
    if(
    $fsize_kb=="0" ){
    print(
    "<b>$fsize</b> Bytes" );}
    elseif(
    $fsize_kb!="0" ){
    print(
    "<b>$fsize_kb</b> KB" );}
    print 
    " ---------- $changeddate<br>";
    }
    if(
    strstr($npart,$ext[1])){
    $name=str_replace($ext[1],"",$npart);
    $fsize=filesize($npart);
    $fsize_kb=(int)($fsize/1000);
    $lastchanged=filectime($npart);
    $changeddate=date("d.m.Y",$lastchanged);
    print(
    "<img src=""$icon[0]> <a href=""\"$npart\" target=_blank>$name.GIF</a> ---------- " );
    if(
    $fsize_kb=="0" ){
    print(
    "<b>$fsize</b> Bytes" );}
    elseif(
    $fsize_kb!="0" ){
    print(
    "<b>$fsize_kb</b> KB" );}
    print 
    " ---------- $changeddate<br>";
    }
    if(
    strstr($npart,$ext[2])){
    $name=str_replace($ext[2],"",$npart);
    $fsize=filesize($npart);
    $fsize_kb=(int)($fsize/1000);
    $lastchanged=filectime($npart);
    $changeddate=date("d.m.Y",$lastchanged);
    print(
    "<img src=""$icon[1]> <a href=""\"$npart\" target=_blank>$name.jpg</a> ---------- " );
    if(
    $fsize_kb=="0" ){
    print(
    "<b>$fsize</b> Bytes" );}
    elseif(
    $fsize_kb!="0" ){
    print(
    "<b>$fsize_kb</b> KB" );}
    print 
    " ---------- $changeddate<br>";
    }
    if(
    strstr($npart,$ext[3])){
    $name=str_replace($ext[3],"",$npart);
    $fsize=filesize($npart);
    $fsize_kb=(int)($fsize/1000);
    $lastchanged=filectime($npart);
    $changeddate=date("d.m.Y",$lastchanged);
    print(
    "<img src=""$icon[1]> <a href=""\"$npart\" target=_blank>$name.JPG</a> ---------- " );
    if(
    $fsize_kb=="0" ){
    print(
    "<b>$fsize</b> Bytes" );}
    elseif(
    $fsize_kb!="0" ){
    print(
    "<b>$fsize_kb</b> KB" );}
    print 
    " ---------- $changeddate<br>";
    }
    if(
    strstr($npart,$ext[4])){
    $name=str_replace($ext[4],"",$npart);
    $fsize=filesize($npart);
    $fsize_kb=(int)($fsize/1000);
    $lastchanged=filectime($npart);
    $changeddate=date("d.m.Y",$lastchanged);
    print(
    "<img src=""$icon[1]> <a href=""\"$npart\" target=_blank>$name.jpeg</a> ---------- " );
    if(
    $fsize_kb=="0" ){
    print(
    "<b>$fsize</b> Bytes" );}
    elseif(
    $fsize_kb!="0" ){
    print(
    "<b>$fsize_kb</b> KB" );}
    print 
    " ---------- $changeddate<br>";
    }
    if(
    strstr($npart,$ext[5])){
    $name=str_replace($ext[5],"",$npart);
    $fsize=filesize($npart);
    $fsize_kb=(int)($fsize/1000);
    $lastchanged=filectime($npart);
    $changeddate=date("d.m.Y",$lastchanged);
    print(
    "<img src=""$icon[1]> <a href=""\"$npart\" target=_blank>$name.JPEG</a> ---------- " );
    if(
    $fsize_kb=="0" ){
    print(
    "<b>$fsize</b> Bytes" );}
    elseif(
    $fsize_kb!="0" ){
    print(
    "<b>$fsize_kb</b> KB" );}
    print 
    " ---------- $changeddate<br>";
    }
    if(
    strstr($npart,$ext[6])){
    $name=str_replace($ext[6],"",$npart);
    $fsize=filesize($npart);
    $fsize_kb=(int)($fsize/1000);
    $lastchanged=filectime($npart);
    $changeddate=date("d.m.Y",$lastchanged);
    print(
    "<img src=""$icon[2]> <a href=""\"$npart\" target=_blank>$name.bmp</a> ---------- " );
    if(
    $fsize_kb=="0" ){
    print(
    "<b>$fsize</b> Bytes" );}
    elseif(
    $fsize_kb!="0" ){
    print(
    "<b>$fsize_kb</b> KB" );}
    print 
    " ---------- $changeddate<br>";
    }
    if(
    strstr($npart,$ext[7])){
    $name=str_replace($ext[7],"",$npart);
    $fsize=filesize($npart);
    $fsize_kb=(int)($fsize/1000);
    $lastchanged=filectime($npart);
    $changeddate=date("d.m.Y",$lastchanged);
    print(
    "<img src=""$icon[2]> <a href=""\"$npart\" target=_blank>$name.BMP</a> ---------- " );
    if(
    $fsize_kb=="0" ){
    print(
    "<b>$fsize</b> Bytes" );}
    elseif(
    $fsize_kb!="0" ){
    print(
    "<b>$fsize_kb</b> KB" );}
    print 
    " ---------- $changeddate<br>";
    }
    if(
    strstr($npart,$ext[8])){
    $name=str_replace($ext[8],"",$npart);
    $fsize=filesize($npart);
    $fsize_kb=(int)($fsize/1000);
    $lastchanged=filectime($npart);
    $changeddate=date("d.m.Y",$lastchanged);
    print(
    "<img src=""$icon[3]> <a href=""\"$npart\" target=_blank>$name.mid</a> ---------- " );
    if(
    $fsize_kb=="0" ){
    print(
    "<b>$fsize</b> Bytes" );}
    elseif(
    $fsize_kb!="0" ){
    print(
    "<b>$fsize_kb</b> KB" );}
    print 
    " ---------- $changeddate<br>";
    }
    if(
    strstr($npart,$ext[9])){
    $name=str_replace($ext[9],"",$npart);
    $fsize=filesize($npart);
    $fsize_kb=(int)($fsize/1000);
    $lastchanged=filectime($npart);
    $changeddate=date("d.m.Y",$lastchanged);
    print(
    "<img src=""$icon[3]> <a href=""\"$npart\" target=_blank>$name.MID</a> ---------- " );
    if(
    $fsize_kb=="0" ){
    print(
    "<b>$fsize</b> Bytes" );}
    elseif(
    $fsize_kb!="0" ){
    print(
    "<b>$fsize_kb</b> KB" );}
    print 
    " ---------- $changeddate<br>";
    }
    if(
    strstr($npart,$ext[10])){
    $name=str_replace($ext[10],"",$npart);
    $fsize=filesize($npart);
    $fsize_kb=(int)($fsize/1000);
    $lastchanged=filectime($npart);
    $changeddate=date("d.m.Y",$lastchanged);
    print(
    "<img src=""$icon[4]> <a href=""\"$npart\" target=_blank>$name.swf</a> ---------- " );
    if(
    $fsize_kb=="0" ){
    print(
    "<b>$fsize</b> Bytes" );}
    elseif(
    $fsize_kb!="0" ){
    print(
    "<b>$fsize_kb</b> KB" );}
    print 
    " ---------- $changeddate<br>";
    }
    if(
    strstr($npart,$ext[11])){
    $name=str_replace($ext[11],"",$npart);
    $fsize=filesize($npart);
    $fsize_kb=(int)($fsize/1000);
    $lastchanged=filectime($npart);
    $changeddate=date("d.m.Y",$lastchanged);
    print(
    "<img src=""$icon[4]> <a href=""\"$npart\" target=_blank>$name.SWF</a> ---------- " );
    if(
    $fsize_kb=="0" ){
    print(
    "<b>$fsize</b> Bytes" );}
    elseif(
    $fsize_kb!="0" ){
    print(
    "<b>$fsize_kb</b> KB" );}
    print 
    " ---------- $changeddate<br>";
    }
    }
    ?>

  2. #2
    if($awake){code();} PHP John's Avatar
    Join Date
    Jul 2002
    Location
    Along the Wasatch Fault line.
    Posts
    1,771
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Do you want someone to do the work FOR you, or do you just want an expample to follow for future coding?
    John

  3. #3
    SitePoint Addict sleepingdanny's Avatar
    Join Date
    Oct 2002
    Location
    Israel
    Posts
    270
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I just want an example for how can I arrange this script so it wont be so messy...
    Danny Grubman @ http://www.our-network.net
    "Intellectuals solve problems; geniuses prevent them."

  4. #4
    gingham dress, army boots... silver trophy redux's Avatar
    Join Date
    Apr 2002
    Location
    Salford / Manchester / UK
    Posts
    4,838
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    simple...indent your code blocks, add a bit more space so it's actually readable by a human being, and don't use elseif when it's not needed...

    e.g.
    Code:
    if($fsize_kb=="0" ){
    print("<b>$fsize</b> Bytes" );}
    elseif($fsize_kb!="0" ){
    print("<b>$fsize_kb</b> KB" );}
    becomes
    Code:
    if ($fsize_kb=="0" ) {
        print("<b>$fsize</b> Bytes" );
    } else {
        print("<b>$fsize_kb</b> KB" );
    }
    and occasional comments that explain what's actually going on wouldn't go amiss either
    re·dux (adj.): brought back; returned. used postpositively
    [latin : re-, re- + dux, leader; see duke.]
    WaSP Accessibility Task Force Member
    splintered.co.uk | photographia.co.uk | redux.deviantart.com

  5. #5
    if($awake){code();} PHP John's Avatar
    Join Date
    Jul 2002
    Location
    Along the Wasatch Fault line.
    Posts
    1,771
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Here is a sample of how I would format it.
    Indent your nested conditions, your loops, and your HTML. Make your variables mean something, not cryptic $a and $xhe's. It makes it easier to read.
    Comment your code so that you know what the heck you did when you come back to it months later with changes to make.

    PHP Code:
    <?
    include("config.php" );
    $icon=array("[url=http://www.site.net/TypeGIF.gif</a]http://www.site.net/TypeGIF.gif</a[/url]>",
                
    "[url=http://www.site.net/TypeJPG.gif</a]http://www.site.net/TypeJPG.gif</a[/url]>",
                
    "[url=http://www.site.net/TypeBMP.gif</a]http://www.site.net/TypeBMP.gif</a[/url]>",
                
    "[url=http://www.site.net/TypeMIDI.gif</a]http://www.site.net/TypeMIDI.gif</a[/url]>",
                
    "[url=http://www.site.net/TypeSWF.gif</a]http://www.site.net/TypeSWF.gif</a[/url]>",);
                
    $ext=array(".gif",".GIF",".jpg",".JPG",".jpeg",".JPEG",".bmp",".BMP",".mid",".MID",".swf",".SWF");
    if(
    is_dir($dir))
    {
      [
    email=$fd=@opendir($dir]$fd=@opendir($dir[/email] [email=$fd=@opendir($dir]$fd=@opendir($dir[/email]) or die("Unable To Open The Folder, Please Email The <b>Webmaster</b>." );
      while(([
    email=$part=@readdir($fd))==true]$part=@readdir($fd))==true[/email]){
      if(
    $part!="." && $part!=".." ){
      
    $file_array[]=$part;}
    }
    if(
    $fd==true)
    {
      
    closedir($fd);}
    }
    sort($file_array);
    for(
    $i=0$i<count($file_array); $i++)
    {
      
    $npart=$file_array[$i];
      if(
    strstr($npart,$ext[0]))
      {
        
    $name=str_replace($ext[0],"",$npart);
        
    $fsize=filesize($npart);
        
    $fsize_kb=(int)($fsize/1000);
        
    $lastchanged=filectime($npart);
        
    $changeddate=date("d.m.Y",$lastchanged);
        print(
    "<img src=""$icon[0]> <a href=""\"$npart\" target=_blank>$name.gif</a> ---------- " );
        if(
    $fsize_kb=="0" )
        {
          print(
    "<b>$fsize</b> Bytes" );
        }
        elseif(
    $fsize_kb!="0" )
        {
          print(
    "<b>$fsize_kb</b> KB" );
        }
        print 
    " ---------- $changeddate<br>";
      }
      if(
    strstr($npart,$ext[1]))
      {
        
    $name=str_replace($ext[1],"",$npart);
        
    $fsize=filesize($npart);
        
    $fsize_kb=(int)($fsize/1000);
        
    $lastchanged=filectime($npart);
        
    $changeddate=date("d.m.Y",$lastchanged);
        print(
    "<img src=""$icon[0]> <a href=""\"$npart\" target=_blank>$name.GIF</a> ---------- " );
        if(
    $fsize_kb=="0" )
        {
          print(
    "<b>$fsize</b> Bytes" );
        }
          elseif(
    $fsize_kb!="0" )
        {
        print(
    "<b>$fsize_kb</b> KB" );
      }
      print 
    " ---------- $changeddate<br>";
    }
    John

  6. #6
    if($awake){code();} PHP John's Avatar
    Join Date
    Jul 2002
    Location
    Along the Wasatch Fault line.
    Posts
    1,771
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    The BBS screws up the code, and removed the line spaces...
    John

  7. #7
    SitePoint Addict sleepingdanny's Avatar
    Join Date
    Oct 2002
    Location
    Israel
    Posts
    270
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks!! Is there a way that will allow me to choose what extentions I allow to see without writing the same code for every extention??
    Danny Grubman @ http://www.our-network.net
    "Intellectuals solve problems; geniuses prevent them."

  8. #8
    if($awake){code();} PHP John's Avatar
    Join Date
    Jul 2002
    Location
    Along the Wasatch Fault line.
    Posts
    1,771
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Use a function or a class for code that you will reuse a lot within your script.
    John

  9. #9
    SitePoint Addict sleepingdanny's Avatar
    Join Date
    Oct 2002
    Location
    Israel
    Posts
    270
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    That's my problem, I don't know what functions I can use... I mean...

    PHP Code:
    <?
    function action()
    {
    .....
    }
    ?>
    Can you tell me what can I do??
    Danny Grubman @ http://www.our-network.net
    "Intellectuals solve problems; geniuses prevent them."

  10. #10
    if($awake){code();} PHP John's Avatar
    Join Date
    Jul 2002
    Location
    Along the Wasatch Fault line.
    Posts
    1,771
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    SleepingDanny,

    I've read some of your other posts. It's time to wake up and do some book work, make mistakes and do some more book work.
    John


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •