Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    New to the CF scene
    Join Date
    Jun 2006
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    setting chmod of uploaded image file

    Hi All

    can anyone please help. Im a noob and Ive been trying to set the chmod of uploaded images in this script for days!... I appreciate your help im trying to set images to 755.

    Thanks so much!
    Dan

    Code:
    <? include '../common.php';
       session_start(); 
       $Err=0;
       $GLOBALS["message"]="";
      if($act=='logout')
      {
      session_unregister("admin_id");
      header("Location:index.php");
    
      }
      if($admin_id=="")
      {
        header("Location:index.php");
      }
    
    
      function check_empty($cd_title,$cd_desc,$cd_image,$cd_url,$cd_url2)
      {
    
           if($cd_title=="" || $cd_desc=="" ||  $cd_image=="" || $cd_url=="")
            {
              if($cd_title=="")
            {
              $GLOBALS["message"]=$GLOBALS["message"]."Please enter CD Title"."<br>";
            }
            if($cd_desc=="")
            {
              $GLOBALS["message"]=$GLOBALS["message"]."Please enter CD Description"."<br>";
            }
              if($cd_image_size=="")
            {
              $GLOBALS["message"]=$GLOBALS["message"]."Please enter CD Image"."<br>";
            }
            if($cd_url=="")
            {
              $GLOBALS["message"]=$GLOBALS["message"]."Please enter CD URL Link"."<br>";
            }
              return 1;
            }
            else
            {
              return 0;
            }
      }
    
    
      function checkUrl(&$cd_url)
      {
            if (!(eregi("^((ht|f)tp://)((([a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3}))|(([0-9]{1,3}\.){3}([0-9]{1,3})))((/|\?)[a-z0-9~#%&'_\+=:\?\.-]*)*)$",$cd_url)))
            {$cd_url="http://".$cd_url;}
    
            if (!(eregi("^((ht|f)tp://)((([a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3}))|(([0-9]{1,3}\.){3}([0-9]{1,3})))((/|\?)[a-z0-9~#%&'_\+=:\?\.-]*)*)$",$cd_url)))
            {
             $GLOBALS["message"]="Url is not valid.";
             $cd_url="";
             return 1;
            }else{return 0;}
      }
    
    
    if($action=="add")
    {
       #CHECK FOR VALIDATION
        
        $Err=0;
        $Err=check_empty($cd_title,$cd_desc,$cd_image,$cd_url,$cd_url2);
        
        
         if($Err==0)
         {
             if($cd_url!="")
             {
                 $cd_url="http://".$cd_url;
                 $cd_url=str_replace("http://http://","http://",$cd_url);
                 $Err=checkUrl(&$cd_url);
             }
         }
        
        
        if($Err==0)
         {
               if($cd_image_type == 'application/octet-stream')
               {
                  $GLOBALS["message"]=$GLOBALS["message"].'Please specify a photo';
                  $dophoto =1;
               }
               elseif( $cd_image_type !='image/pjpeg' && $cd_image_type !='image/gif')
               {
                  $GLOBALS["message"]=$GLOBALS["message"].'Please specify a gif/jpeg photo file';
                  $dophoto =1;
               }
         }    
         
        if($Err==0 && $dophoto!=1)
        {
           
           #SET THE ID
           $sql="select max(cd_id) as max from tblcd4";
           $result=mysql_query($sql);
           $row=mysql_fetch_object($result);
           $id=$row->max + 1;
           mysql_free_result($result);
    
           $ext1=stristr($cd_image_name,".");
            $ext1=strtolower($ext1);
            $fname="CD$id$ext1";
           $upload1="../cd_image4/".$fname;
           move_uploaded_file($cd_image,$upload1);
    
           $pdate=date("Y-m-d");
           $sql="insert into tblcd4 (cd_title,cd_desc,cd_image,cd_url,cd_url2,pdate,price,price2) values('$cd_title','$cd_desc','$fname','$cd_url','$cd_url2','$pdate','$price','$price2')";
    
           mysql_query($sql)or die("Error");
            header("Location:confirm_cd4.php?flag=cd");
         }
    }   
    ?>

  • #2
    Senior Coder angst's Avatar
    Join Date
    Apr 2004
    Location
    Toronto, Ontario
    Posts
    2,114
    Thanks
    15
    Thanked 122 Times in 122 Posts
    well, this is from the manual.

    PHP Code:
    <?php
    // Read and write for owner, nothing for everybody else
    chmod("/somedir/somefile"0600);

    // Read and write for owner, read for everybody else
    chmod("/somedir/somefile"0644);

    // Everything for owner, read and execute for others
    chmod("/somedir/somefile"0755);

    // Everything for owner, read and execute for owner's group
    chmod("/somedir/somefile"0750);
    ?>

    but I do know that this wont work on most shared servers.
    try calling your host to find out if this is allowed.

    -Ken


  •  

    Posting Permissions

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