2012-09-25 5 views
-2

내 status.txt 파일을 social이라는 특정 디렉토리에 저장하려고합니다. 나는 사회적 디렉토리를 만들었지 만, 어떤 이유로 status.txt라는 이름은 socialstatus.txt이고 status.txt 파일은 소셜 디렉토리가 아닌, 소셜 디렉토리가있는 같은 폴더에 있습니다. 당신을 혼란스럽게합니다.)파일이 특정 폴더에 저장되지 않았습니다 (디렉토리 생성)

나는 이것을하려고하지만 코드의 배치와 관련이있는 것 같습니다 ... 파일을 디렉토리에 저장하는 것은 if (! file_exists ($ newdir)) {

은 큰 도움이

<?php 

$newdir = "../../data/social"; 
umask(0007); 



$errors = array(); 
$permissionsArray = (isset($_POST['permission']) ? $_POST['permission'] : null); 


if (isset($_POST["statuscode"])) 
{ 
    $statusCode = $_POST["statuscode"]; 
    $patternCode = "/^S[0-9]{4}$/"; 
    if (preg_match($patternCode, $statusCode)) 
    { 
     $ans = ""; 
     $length = strlen($statusCode); 
     echo $statusCode . "<br />"; 
    } 
} 
else 
{ 
    array_push($errors, "Please fill in Status Code as they are mandatory field"); 
} 

if (isset ($_POST["status"])) 
{ 
    $status = $_POST["status"]; 
    $pattern = "/^[a-zA-Z0-9\s\.,!?]*$/"; 
    if (preg_match($pattern, $status)) 
    { 
     echo $status . "<br />"; 
    } 
} 
else 
{ 
    array_push($errors, "<b>Error:</b> Please fill in Status as they are mandatory field!"); 
} 

if (isset ($_POST["share"])) 
{ 
    $shareButton = $_POST["share"]; 
    echo $shareButton . "<br />"; 
} 
else 
{ 
    //Not possible unless in exceptional circumstances 
    array_push($errors, "Please choose a share"); 
} 

if (isset($_POST["date"])) 
{ 
    $date = date("d/m/y"); 
    echo $date . "<br />"; 
} else { 
    $date = $_POST["date"]; 
} 

if (isset($permissionsArray)) 
{ 
    foreach($permissionsArray as $permission){ 
     echo $permission . "<br />"; 
    } 
} 

if(!file_exists($newdir)){ 
    mkdir($newdir, 02770); 

$statusTxt = fopen($newdir. "status.txt", "a"); 

if (is_writeable($newdir. "status.txt")) { 
    if (fwrite($statusTxt, $statusCode . " " . $status . " " . $shareButton . " " . $date . " " . $permission . "\n")) 
{ 
} 
    echo "<p>Your form has succesfully been submit!</p>"; 
} 
fclose($statusTxt); 
} 


if(isset($statusCode, $status)) 
{ 
    //if(empty($statusCode) || empty($status)) 
    //{ 
    //array_push($errors, "Please fill in the required part!"); 
    //} 
    if (0 === strlen($statusCode > 5 || $statusCode < 5)) 
    { 
     array_push($errors, "<b>Error:</b> You characters length is either less or more than 5 characters<br/>"); 
    } 
    if (0 === preg_match("/\S+/", $statusCode)) 
    { 
     array_push($errors, "<b>Error:</b> You forgot to fill in Status Code!<br/>"); 
    } 
    if (0 === preg_match("/\S+/", $status)) 
    { 
     array_push($errors, "<b>Error:</b> You forgot to fill in the Status! <br/>"); 
    } 
    if (0 === preg_match($patternCode, $statusCode)) 
    { 
     array_push($errors, "<b>Error:</b> please make sure that the first letter in Status Code is uppercase 'S' following by 4 numbers. <br/>"); 
    } 
    if (0 === preg_match($pattern, $status)) 
    { 
     array_push($errors, "<b>Error:</b> Please make sure to avoid symbols other than \",.?!\" <br/>"); 
    } 
} 


if (isset($errors)) 
{ 
    foreach ($errors as $error) 
    { 
     echo '<strong>', $error, '</strong>'; 
    } 
} 

echo '<a href="phpstatusform.php">Back to Form page.</a> <br />'; 

echo '<a href="index.php">Back to Home page.</a>'; 


?> 
+1

정말로, 파일 이름을 설정하는 위치에'/'를 추가하라고 지시해야합니까? –

+0

오, 이런, 어떻게 그리울 수 있을까? -_- –

+0

출력 파일 이름이 무엇인지 알지 못했습니까? 내가 원하는'socialstatus.txt'와'social \ status.txt'의 차이는 무엇입니까? –

답변

0

$ NEWDIR = "../../data/socia 주셔서 너무 감사 l ";
$ statusTxt = fopen ($ newdir. "status.txt", "a");

가변 교체

...

$의 statusTxt =하면 fopen ("../../data/social" "한 Status.txt", "A").;
누락되었습니다/

관련 문제