-1

I am trying to create a site, where user can create his account and automatic create his folder in my host.
I write this :

$addtothedb="INSERT INTO login(firstname,lastname,useremail,password,Gender,Dateofbirth) VALUES ('". $fristname . "','". $laname ."','" . $email . "','". $pass ."')" ;          
$result=mysqli_query($con,$addtothedb);
$cur = "USERS/";
$gofile=$cur.$email;
if($result){
   if ( mkdir($gofile,0777) ) {
     } else {
      }
   echo "  Account Successfully Created. <br> Now you can Login. ";                       
  } 
  else {
   echo "<center>Failure</center>";
}

So now he uploads his photos. I want that photos go to his folder not in USERS/ Directory. I try this script but doesnt work, how I want.

<?php
     $con = mysqli_connect("localhost","root","","test");
     echo $_SESSION['name']."<br />" ;  
    $cur = "USERS/";
    $gofile=$cur .$_SESSION["name"];
    echo $gofile;

    $des= dirname($gofile.'/'.$_SESSION['name']);echo "<br/>";  
    echo $des;
?>
4

2 回答 2

1

您的变量 $gofile 没有按照您的预期构建。输出将类似于:

USERS/pokeybit/pokeybit

$des 应该是:

$des=$cur."/".$_SESSION['name']; //for the path to be "USERS/pokeybit"
$des=$_SESSION['name']; //for the path to be "pokeybit"
$des="../".$_SESSION['name']; //for the path to be "parent_folder/pokeybit"
于 2015-03-25T18:41:36.257 回答
0

您的脚本无法上传文件并将其放入目录中。首先你需要一个表格,我有一个基本的上传脚本来帮助你。

XHTML 表单

<form action="accept-file.php" method="post" enctype="multipart/form-data">
    Your Photo: <input type="file" name="photo" size="25" />
    <input type="submit" name="submit" value="Submit" />
</form>

您需要为表单的 enctype 属性使用 multipart/form-data 值。您显然还需要至少一个文件类型的输入元素。表单的动作标签必须提供一个 URL,该 URL 指向一个包含下面 PHP 片段的文件。PHP的

//if they DID upload a file...
if($_FILES['photo']['name'])
{
    //if no errors...
    if(!$_FILES['photo']['error'])
    {
        //now is the time to modify the future file name and validate the file
        $new_file_name = strtolower($_FILES['photo']['tmp_name']); //rename file
        if($_FILES['photo']['size'] > (1024000)) //can't be larger than 1 MB
        {
            $valid_file = false;
            $message = 'Oops!  Your file\'s size is to large.';
        }

        //if the file has passed the test
        if($valid_file)
        {
            //move it to where we want it to be
            move_uploaded_file($_FILES['photo']['tmp_name'], 'uploads/'.$new_file_name);
            $message = 'Congratulations!  Your file was accepted.';
        }
    }
    //if there is an error...
    else
    {
        //set that to be the returned message
        $message = 'Ooops!  Your upload triggered the following error:  '.$_FILES['photo']['error'];
    }
}

//you get the following information for each file:
$_FILES['field_name']['name']
$_FILES['field_name']['size']
$_FILES['field_name']['type']
$_FILES['field_name']['tmp_name']
于 2015-03-25T18:43:04.903 回答