-2
我嘗試我的文件status.txt中保存到特定的目錄中所謂的社會。我創建了社會目錄,但由於某種原因,我的status.txt將其名稱命名爲socialstatus.txt,並且status.txt文件不在社交目錄內,而是位於社交目錄所在的同一文件夾中(我希望我不會)文件沒有保存到特定的文件夾(創建目錄)
我試圖做到這一點,但它似乎與代碼的位置有關... 那些編碼保存文件到目錄是一個開始如果(!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>';
?>
真的,你需要我們來告訴你添加一個'/'到您正在設置文件名? –
哦,天哪,我怎麼能錯過-_- –
沒有它似乎是顯而易見的給你的輸出文件的名稱是什麼?我的意思是你所希望的'socialstatus.txt'和'social \ status.txt'有什麼不同? –