Hi im having trouble getting a chmod script to work for my CMS im building can anyone help me?

    Are you sure you have permission to chmod? A lot of hosting companies disallow that command as it can be harmful if used wrong.

      I assume you have a website and have built a cms to manage the content. I recently ran into the same issues with ftp functions and permissions for uploading files to the server. The solution I found to work is to use the $_FILE['var_name'] to get the varibles from the form such as uploading an image file or word document. I wrote a nice script to use ftp functions but ran into problems. You might look at these links for more info.

      http://us2.php.net/manual/en/function.ftp-chmod.php

      function upload ($filename) {
      $item['tmp_name'] = $filename['tmp_name'];
      $item['name'] = $filename['name'];
      $item['size'] = $filename['size'];
      $item['type'] = $filename['type'];

         // here you have code to determine if  the file
         // has the right extension such as .jpg .gif .doc .rtf etc..
         // you could also use the varible for size to determine
         // if the file is a certain size ex. 
         // if ($item['size'] >= 50000) {
         // greater than 50Kb print some error
         // the file will be stored in a temp directory 
         // and givin a tmp name
         // say on your form you have an
         // <input type="file" name="upload" value="Upload!">
         // you would have to use in your form tag
         // type="multipart/formdata" or it won't upload to the server
         // the name will take the path of the upload ex.
         // C:\iimage\myphoto.jpg 
         // and strip all the directory info and give the name of the 
         // file which would be "myphoto.jpg"
      
         $foldertophotosonserver = "/images/"
         copy($item['tmp_name'],$foldertophotosonserver.$item['name']);
      
         // put in some error checking 

      } // end function upload

      check out the php.net site, it has manuals for everything :-D

        yeah i was working off the php.net website but i cant get it to work... i want it so when they are using the install.php in will chmod the files when they are on the step for that... but the script i using is

        chmod("users.php", 0755);

        thats an example of the way im trying to chmod... and this is the error message bellow

        Warning: chmod(): Operation not permitted in /home/aenima/public_html/SHADOWED/install.php on line 296

        it shud be able to work on my server ive used e107 and other CMS's that have automatic chmoding

          my friend said that this would be the best way to work the script....

          $files = "code.php:0666,config.php:0666,index_content.php:0666,header.php:0666,footer.php:0666,control_content.php:0666,users/:0777,includes/styles.php:0666,creation_log.php:0666,guests_online.php:0666";
          $mod_dir = "";
          $dir = "modules";
          $handle=@opendir($dir);
          $dir_arr = array();
          while ($file = readdir($handle)) {
          if ($file != "." && $file != ".." && $file != "index.html") {
          if(is_dir($dir."/".$file)) {
          if(file_exists($dir."/".$file."/chmod.php")) {
          if(!instr("\$files",rf($dir."/".$file."/chmod.php"))) {
          $chmod = "";
          require($dir."/".$file."/chmod.php");
          if($chmod != "") {
          $mod_dir = $dir."/".$file;
          $chmod_arr = explode(",",$chmod);
          $new_list = "";
          foreach($chmod_arr as $single_chmod) {
          $sc_arr = explode(":",$single_chmod);
          $files = $files.",".$mod_dir."/".$sc_arr[0].":".$sc_arr[1];
          }
          }
          }
          }
          }
          }
          }
          $files_arr = explode(",",$files);
          $file_list = "";
          $command_line1 = "";
          $command_line2 = "";
          foreach($files_arr as $single_file) {
          $sf_arr = explode(":",$single_file);
          if(@chmod($sf_arr[0], $sf_arr[1])) { echo $sf_arr[1]." :: CHMOD Successful.<br />\n"; }
          echo @shell_exec("chmod ".$sf_arr[1]." ".$sf_arr[0]);
          $command_line1 = $command_line1."chmod ".$sf_arr[1]." ".$sf_arr[0].";";
          $command_line2 = $command_line2."site chmod ".$sf_arr[1]." ".$sf_arr[0].";";
          $file_list = $file_list.$sf_arr[0]." <i>".$sf_arr[1]."<br>";
          }
          echo "Attempting to write a file.<br />";
          if(@wf("code.php","w","<?php\n\$xcode = \"*\";\n?>")) {
          echo "<font style='font-size: 13px; font-family: Arial; font-weight: bold;'>Successful</font>";
          }
          else {
          echo "<font style='font-size: 13px; font-family: Arial; font-weight: bold; color: #FF0000;'>Error</font>";
          }
          echo <<<HTML
          <br /><br />
          <b>If CHMOD was not successful above then CHMOD the following files before continuing:</b><br /><br />
          $file_list<br /><br />
          <b>Command Lines:</b><br /><br />
          $command_line1<br /><br />
          or<br /><br />
          $command_line2<br /><br />
          <form action="$self" method="POST">
          HTML;

            Write a Reply...