Results 1 to 3 of 3

Thread: Help with PHP for my CSM please

  1. #1
    Join Date
    Dec 2005
    Posts
    49
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Question Help with PHP for my CSM please

    PHP Code:
    <?

    /************************************************************
     *     Setup variables
     ************************************************************/
    $site_name $_SERVER['HTTP_HOST'];

    $upload_dir "../images/gallery/photos/thumbnails/";
    $upload_dir2 "../images/gallery/photos/";
    $message ="";

    /************************************************************
     *     List Files
     ************************************************************/

    $handle=opendir($upload_dir);
    $filelist "";
    while (
    $file readdir($handle)) {
       if(!
    is_dir($file) && !is_link($file) && substr($file, -44) == ".jpg") {
          
    $filelist.="<a href='?del=$upload_dir$file&&?del=$upload_dir2$file' title='delete'><img src='".$upload_dir."".$file."' border='0'></a>";
          
    $filelist.="&nbsp;";
       }
    }

    /************************************************************
     *     Process User's Request
     ************************************************************/

    if ($_REQUEST[del])  {
        
    unlink($_REQUEST[del]);
        print 
    "<script>window.location.href='?message=deleted successfully'</script>";
    }

    /************************************************************/

    ?>
    <div align="left"><font color=red><?=$_REQUEST[message]?></font>
    <br>
    <br>
    <b>Gallery Images</b>
    </div>
    <hr align="left" width=70%>
    <div align="left">Click the thumbnail to delete an image<br/>
      <br/>
      <strong><font color="#FF0000">WARNING!</font></strong><br/>
    Do NOT Click a on any image, unless your ABSOLUTELY CERTAIN that you wish to remove the file.<br/>
    <br/>
    <?=$filelist?>
    </div>
    ok, so i am trying to make it so the user can click on the image and remove the specific image from the gallery. right now it works to remove the thumbnail, but i need it to remove the large image too. is it possible to do this? here is the code for the image link.

    PHP Code:
    $filelist.="<a href='?del=$upload_dir$file&&?del=$upload_dir2$file' title='delete'><img src='".$upload_dir."".$file."' border='0'></a>"
    as you can see, i am calling $upload_dir$file and then trying to call the second path in the same link with &&?del=$upload_dir2$file. So, like i was saying, it removes the thumbnail, but i need it to remove the large image too. please help. let me know if this is possible, or do i need to just call the delete function with the link to remove the thumbnail, and then somehow tell it to go to a second function and remove the same file name from the second location? thanks in advance to anyone that can help.

    p.s. the reason i posted the entire code is so that you can go back and see what functions are being called to make this all work, not to have you code something for me. see what you guys/gal can do. thanks again.

  2. #2
    Join Date
    May 2006
    Posts
    12
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Firstly, I would like to say that this post was the reason why I joined; I think I can more than help.

    Your script has a few problems, or code that I would most definately alter. Like the way you detect the extension from this line:

    Code:
    if(!is_dir($file) && !is_link($file) && substr($file, -4, 4) == ".jpg") {
    Sure that works fine, but it is not good coding practise, because some people might want to upload a gif instead, which would be not a problem if your hosting jpg only files.

    Another problem is that some applications save as .JPG and even .JPEG, so you might want to ammend you line to this:

    Code:
    $file = strtolower($file);
    $is_jpg = substr($file, -4,4);
    $is_jpeg = substr($file, -5,5);
    if(!is_dir($file) && !is_link($file) && $is_jpg === ".jpg" || $is_jpeg === ".jpeg") {
    That is the first problem rectified. I will look into the other problem within this hour.

  3. #3
    Join Date
    Dec 2005
    Posts
    49
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    sorry it took so long for me to respond, i actually posted this on FWS also, and have gotten the problem resolved and the CMS if finished. the user wont be using any gif images, but maybe i will ad it in anyways. thanks for your advise.

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
  •