Login | Register | FAQ
Anonymous

Please tell how to do this

+ Post a reply

18 posts 1, 2


Please tell how to do this

by amanpoke » Tue Apr 24, 2012 10:27 am

I have just added a new function to my site.

But the trouble I have is that that the function is creating new directories in the public_html/"username"

And I want it to make these directories in the following directory:
public_html/users/"username"

My code is this:
Code: Select all
<?php
session_start();
include "db_connect.php";

if($_SESSION['id'])
{
   $sql = "SELECT username FROM `users` WHERE `id`='".$_SESSION['id']."'";
   $res = mysql_query($sql) or die(mysql_error());
   
   if(mysql_num_rows($res) != 1)
   {
      session_destroy();
      echo "<script language=\"Javascript\" type=\"text/javascript\">document.location.href='index.php'</script>";
   }
   else
   {
   $row = mysql_fetch_assoc($res);
   
   $title = protect($_POST['title']);
   
   if(!$title)
   {
      echo "<script language=\"Javascript\" type=\"text/javascript\">
            alert(\"You must choose a title for your picture!\")
            document.location.href='profilecp.php'</script>";
      
   }
   
   $target = $row['username'];
   if(!is_dir($target)) @mkdir($target);
   $target = $target . '/pics';
   
   if(!is_dir($target)) @mkdir($target);
   
      $target = $target."/".basename($_FILES['pics']['name']) ;
      $size = $_FILES['pics']['size'];
      $pic = $_FILES['pics']['name'];
      $type = $_FILES['pics']['type'];
                     
         $sql2= "INSERT INTO `user_photos` (`profile_id`,`title`,`size`,`type`,`reference`)
         VALUES ('".$_SESSION['id']."','$title','$size','$type','$pic'); ";
         
         $res2 = mysql_query($sql2) or die(mysql_error());

            if(move_uploaded_file($_FILES['pics']['tmp_name'], $target))
            {
               echo "<script language=\"Javascript\" type=\"text/javascript\">
               alert(\"Your picture has been uploaded\")
               document.location.href='profilecp.php'</script>";
            }
            else
            {
               echo "<script language=\"Javascript\" type=\"text/javascript\">
               alert(\"There was an error, try again\")
               document.location.href='profilecp.php'</script>";
            }
         
      
      $target2 = $row['username'];
      $target2 = $target2 . '/pics';
      $target2 = $target2 . '/thumbs';
      if(!is_dir($target2)) @mkdir($target2);
      $target2 = $target2."/".basename($_FILES['pics']['name']) ;
      createthumb($target,$target2,150,150);
      
   }
}else echo "<script language=\"Javascript\" type=\"text/javascript\">document.location.href='index.php'</script>";

?>


Please tell me what change I should do in order to do this.
User avatar

amanpoke

  • Posts: 82
  • Joined: Sat Feb 04, 2012 3:20 pm
--
Join Linkbucks and get paid to share your links:
https://www.linkbucks.com/referral/527073

Re: Please tell how to do this

by XainPro » Wed Apr 25, 2012 4:21 pm

Ok you need to modify your code like this


<?php
session_start();

if($_SESSION['id'])
{
$sql = "SELECT username FROM `users` WHERE `id`='".$_SESSION['id']."'";
$res = mysql_query($sql) or die(mysql_error());

if(mysql_num_rows($res) != 1)
{
session_destroy();
echo "<script language=\"Javascript\" type=\"text/javascript\">document.location.href='index.php'</script>";
}
else
{
$row = mysql_fetch_assoc($res);

$title = protect($_POST['title']);

if(!$title)
{
echo "<script language=\"Javascript\" type=\"text/javascript\">
alert(\"You must choose a title for your picture!\")
document.location.href='profilecp.php'</script>";

}

$target = "users/";
$target .= $row['username'];

if(!is_dir($target)) @mkdir($target);
$target = $target . '/pics';

if(!is_dir($target)) @mkdir($target);

$target = $target."/".basename($_FILES['pics']['name']) ;
$size = $_FILES['pics']['size'];
$pic = $_FILES['pics']['name'];
$type = $_FILES['pics']['type'];

$sql2= "INSERT INTO `user_photos` (`profile_id`,`title`,`size`,`type`,`reference`)
VALUES ('".$_SESSION['id']."','$title','$size','$type','$pic'); ";

$res2 = mysql_query($sql2) or die(mysql_error());

if(move_uploaded_file($_FILES['pics']['tmp_name'], $target))
{
echo "<script language=\"Javascript\" type=\"text/javascript\">
alert(\"Your picture has been uploaded\")
document.location.href='profilecp.php'</script>";
}
else
{
echo "<script language=\"Javascript\" type=\"text/javascript\">
alert(\"There was an error, try again\")
document.location.href='profilecp.php'</script>";
}

$target2 = "users";

$target2 .= $row['username'];
$target2 = $target2 . '/pics';
$target2 = $target2 . '/thumbs';
if(!is_dir($target2)) @mkdir($target2);
$target2 = $target2."/".basename($_FILES['pics']['name']) ;
createthumb($target,$target2,150,150);

}
}else echo "<script language=\"Javascript\" type=\"text/javascript\">document.location.href='index.php'</script>";

?>

i just modified 2 lines in your code with are in RED color.
User avatar

XainPro

  • Posts: 3542
  • Joined: Fri Feb 17, 2012 8:10 pm

Re: Please tell how to do this

by amanpoke » Thu Apr 26, 2012 9:58 am

I added the two lines to the code in their respective positions, but it didn't worked as I thought. It created the directories in the public_html/
only.
User avatar

amanpoke

  • Posts: 82
  • Joined: Sat Feb 04, 2012 3:20 pm
--
Join Linkbucks and get paid to share your links:
https://www.linkbucks.com/referral/527073

Re: Please tell how to do this

by XainPro » Thu Apr 26, 2012 12:25 pm

well in your code thi command make directory

mkdir($target2);

you should give proper path to it otherwise it will create directory in public_html
try to run
mkdir($_SERVER['DOCUMENT_ROOT'].$target2);
and
mkdir($_SERVER['DOCUMENT_ROOT'].$target1);
then check.
User avatar

XainPro

  • Posts: 3542
  • Joined: Fri Feb 17, 2012 8:10 pm

Re: Please tell how to do this

by amanpoke » Fri Apr 27, 2012 2:58 pm

Can u plz tell me where I should insert these lines.
User avatar

amanpoke

  • Posts: 82
  • Joined: Sat Feb 04, 2012 3:20 pm
--
Join Linkbucks and get paid to share your links:
https://www.linkbucks.com/referral/527073

Re: Please tell how to do this

by XainPro » Fri Apr 27, 2012 8:17 pm

Ok you need to modify your code like this


<?php
session_start();

if($_SESSION['id'])
{
$sql = "SELECT username FROM `users` WHERE `id`='".$_SESSION['id']."'";
$res = mysql_query($sql) or die(mysql_error());

if(mysql_num_rows($res) != 1)
{
session_destroy();
echo "<script language=\"Javascript\" type=\"text/javascript\">document.location.href='index.php'</script>";
}
else
{
$row = mysql_fetch_assoc($res);

$title = protect($_POST['title']);

if(!$title)
{
echo "<script language=\"Javascript\" type=\"text/javascript\">
alert(\"You must choose a title for your picture!\")
document.location.href='profilecp.php'</script>";

}

$target = "users/";
$target .= $row['username'];

if(!is_dir($target)) mkdir($_SERVER['DOCUMENT_ROOT'].$target);
$target = $target . '/pics';

if(!is_dir($target)) mkdir($_SERVER['DOCUMENT_ROOT'].$target);

$target = $target."/".basename($_FILES['pics']['name']) ;
$size = $_FILES['pics']['size'];
$pic = $_FILES['pics']['name'];
$type = $_FILES['pics']['type'];

$sql2= "INSERT INTO `user_photos` (`profile_id`,`title`,`size`,`type`,`reference`)
VALUES ('".$_SESSION['id']."','$title','$size','$type','$pic'); ";

$res2 = mysql_query($sql2) or die(mysql_error());

if(move_uploaded_file($_FILES['pics']['tmp_name'], $target))
{
echo "<script language=\"Javascript\" type=\"text/javascript\">
alert(\"Your picture has been uploaded\")
document.location.href='profilecp.php'</script>";
}
else
{
echo "<script language=\"Javascript\" type=\"text/javascript\">
alert(\"There was an error, try again\")
document.location.href='profilecp.php'</script>";
}

$target2 = "users";

$target2 .= $row['username'];
$target2 = $target2 . '/pics';
$target2 = $target2 . '/thumbs';

if(!is_dir($target2)) mkdir($_SERVER['DOCUMENT_ROOT'].$target2);
$target2 = $target2."/".basename($_FILES['pics']['name']) ;
createthumb($target,$target2,150,150);

}
}else echo "<script language=\"Javascript\" type=\"text/javascript\">document.location.href='index.php'</script>";

?>
User avatar

XainPro

  • Posts: 3542
  • Joined: Fri Feb 17, 2012 8:10 pm

Re: Please tell how to do this

by amanpoke » Sat Apr 28, 2012 3:28 pm

Again the same thing happened. It created the folder in the public_html only.
If you want I can provide u with the other files also (which ever u ask). If the error is due to those files.
User avatar

amanpoke

  • Posts: 82
  • Joined: Sat Feb 04, 2012 3:20 pm
--
Join Linkbucks and get paid to share your links:
https://www.linkbucks.com/referral/527073

Re: Please tell how to do this

by XainPro » Sat Apr 28, 2012 9:07 pm

ok lets dignose this issue
make a file names
test.php and put this code in it
Code: Select all
<?php
// Desired folder structure
$structure = 'In_Root';
$structure2 = 'the_folder/in_sub_dir';

// to mkdir() must be specified.

mkdir($structure, 0, true);
mkdir($structure2, 0, true);
// ...
?>


and upload it and run it after running it once just goto root directory and check
there should be two new folders in root named In_Root and the_folder.
In_root folder should be empty and the_folder should have in_sub_dir in it.
If these both are created successfully and the structure is same then there should be problem with your code but if these folder is not created in the manner i have told you then there should be problem at your host setting etc.
Regards,
XainPro

Last edited by XainPro on Sun Apr 29, 2012 6:54 am, edited 1 time in total.

User avatar

XainPro

  • Posts: 3542
  • Joined: Fri Feb 17, 2012 8:10 pm

Re: Please tell how to do this

by amanpoke » Sun Apr 29, 2012 5:15 am

It showed the following:

Parse error: syntax error, unexpected T_STRING in /home/a5296422/public_html/test.php on line 9

I tested it on 000webhost.
User avatar

amanpoke

  • Posts: 82
  • Joined: Sat Feb 04, 2012 3:20 pm
--
Join Linkbucks and get paid to share your links:
https://www.linkbucks.com/referral/527073

Re: Please tell how to do this

by XainPro » Sun Apr 29, 2012 6:53 am

ohh sorry this code has syntex error try this code
actually i forgot to enter semicolon at the end
Code: Select all
<?php
// Desired folder structure
$structure = 'In_Root';
$structure2 = 'the_folder/in_sub_dir';

// to mkdir() must be specified.

mkdir($structure, 0, true);
mkdir($structure2, 0, true);
// ...
?>
User avatar

XainPro

  • Posts: 3542
  • Joined: Fri Feb 17, 2012 8:10 pm


+ Post a reply

1, 2

?>