NameSilo

What's wrong with this [CHMOd using Php]

Spaceship Spaceship
Watch
Impact
19
Hey
I am trying to install a script for my schools site but the ftp doesnt give me permissions to change the CHMOD so i got this handy script to do it but its giving me a parse error

PHP:
<?php
if(isset($_POST['dir'])){
$set = chmod($dir, 0.$num);
if(!$set){ echo "Error setting permissions"; } else { echo "Success!"; }

} else {
echo "<form action='$PHP_SELF' method='POST'>
Enter the directory to CHMOD
<input type='text' maxlength='48' length='24' name='dir'><br>
Enter permissions: <input type='text' maxlength='3' length='5' name='num'>
</form>";
}
?>

error is :

Parse error: parse error, unexpected T_VARIABLE in chmod.php on line 3
 
0
•••
The views expressed on this page by users and staff are their own, not those of NamePros.
AfternicAfternic
Try $_POST['dir'] and $_POST['num'] instead of $dir and $num
 
0
•••
PHP:
<?php

if(isset($_POST['dir']))
{
  $set = chmod($_POST['dir'], 0.(int)$_POST['num']);
  if(!$set)
  {
    echo "Error setting permissions";
  }
  else
  {
    echo "Success!";
  }
}
else
{
  echo "<form action='$PHP_SELF' method='POST'>
  Enter the directory to CHMOD
  <input type='text' maxlength='48' length='24' name='dir'><br>
  Enter permissions: <input type='text' maxlength='3' length='5' name='num'>
  </form>";
}
?>

Dan beat me to it :p
 
0
•••
Unless I'm mistaken, you can't chmod a file via php unless php has ownership of the directory or file. :\
 
0
•••
hey second version
i tried tht ..and i get
PHP:
Parse error: parse error, unexpected T_INT_CAST in F:\InetPub\wwwroot\schools\Laurascrds\v2\gallery\chmod.php on line 5

and dan i tried doing wt u told me and i got this
Code:
Parse error: parse error, unexpected T_VARIABLE in F:\InetPub\wwwroot\schools\Laurascrds\v2\gallery\chmod.php on line 3
 
0
•••
Just tested it and it worked for me:

PHP:
<?php

if(isset($_POST['dir']))
{
  $num = '0'.$_POST['num'];
  $dir = $_POST['dir'];
  
  $set = chmod($dir, $num);
  if(!$set)
  {
    echo "Error setting permissions";
  }
  else
  {
    echo "Success!";
  }
}
else
{
  echo '<form action="'.$_SERVER['PHP_SELF'].'" method="POST">
  Enter the directory to CHMOD
  <input type="text" maxlength="48" length="24" name="dir"><br>
  Enter permissions: <input type="text" maxlength="3" length="5" name="num">
  <input type="submit" name="submit" value="CHMOD">
  </form>';
}

?>
 
Last edited:
0
•••
wel the script is on but its not setting permissions
i get

Error setting permissions
 
0
•••
I don't know how you got a different error from what I said.. we said the same thing, he just gave you the whole code.
 
0
•••
Is PHP running at the server level or user? User Apache / Nobody will not be able to modify permissions on files they do not own or are a group of.
 
0
•••
What's the current permission of the file you're trying to CHMOD?
 
0
•••
Your hosting is on windows server ?

Regards
Adrian
 
0
•••
what ftp client are you using? I would suggest not to waste time with the php thing if it doesnt work; try WS_FTP Pro, it'd prolly do the trick!

GoOD LucK!
 
0
•••
If you're on a Windows server, I don't believe that CHMODding works. I think it's just a *NIX thing.
 
0
•••
Tree said:
If you're on a Windows server, I don't believe that CHMODding works. I think it's just a *NIX thing.
not only unix, but linux too :)
 
0
•••
*NIX meaning all flavors of Unix and Linux ;)
 
0
•••
Tree said:
*NIX meaning all flavors of Unix and Linux ;)


:) everyday we get to learn new things... it happens ;)
 
0
•••
Unstoppable Domains
Domain Recover
DomainEasy โ€” Payment Flexibility
  • The sidebar remains visible by scrolling at a speed relative to the pageโ€™s height.
Back