Dynadot Aftermarket: discover domain gems worth investing in. Visit our aftermarket.

What's wrong with this [CHMOd using Php]

SpaceshipSpaceship
SpaceshipSpaceship
SpaceshipSpaceship
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
Close
The views expressed on this page by users and staff are their own, not those of NamePros.
GoDaddyGoDaddy
Try $_POST['dir'] and $_POST['num'] instead of $dir and $num
 
0
Close
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
Close
Unless I'm mistaken, you can't chmod a file via php unless php has ownership of the directory or file. :\
 
0
Close
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
Close
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
Close
wel the script is on but its not setting permissions
i get

Error setting permissions
 
0
Close
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
Close
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
Close
What's the current permission of the file you're trying to CHMOD?
 
0
Close
Your hosting is on windows server ?

Regards
Adrian
 
0
Close
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
Close
If you're on a Windows server, I don't believe that CHMODding works. I think it's just a *NIX thing.
 
0
Close
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
Close
*NIX meaning all flavors of Unix and Linux ;)
 
0
Close
Tree said:
*NIX meaning all flavors of Unix and Linux ;)


:) everyday we get to learn new things... it happens ;)
 
0
Close
Appraise.net

We're social

Escrow.com
Spaceship
Domain Recover
CryptoExchange.com

NamePros updates

Switch between accounts
You can now stay logged in to more than one NamePros account in the same browser. Click your avatar, then "Accounts in this browser", to...
AIVikings
Catchy
  • The sidebar remains visible by scrolling at a speed relative to the page’s height.
Back