file_put_contents()

baiumbg

Registered
Имам проблем с тази функция. Ето ми сорса:

Код:
<?php
echo "Enter the directory and name of the file you wish to edit:<br>";
echo "<form method='post'>";
echo "<input type='text' name='file'><br>";
echo "<input type='submit' name='davai' value='Edit'><br><br></form>";

if(isset($_POST['davai'])) {
$file=$_POST['file'];
$current=file_get_contents($file);
echo "<form method='post'>";
echo "<textarea cols='60' rows='20' name='edit'>".stripslashes($current)."</textarea><br>";
echo "<input type='submit' name='submit' value='Save' action=".$_SERVER['PHP_SELF']."></form>";
if(isset($_POST['submit'])) {
$edited=$_POST['edit'];
file_put_contents($file, stripslashes($edited));
}
}
?>

Обаче нищо не променя...Като махна въвеждането на файл си работи. Ама като го сложа не действа...
 
Код:
 <?php
echo "Enter the directory and name of the file you wish to edit:<br>";
echo "<form method='post'>";
echo "<input type='text' name='file'><br>";
echo "<input type='submit' name='davai' value='Edit'><br><br></form>";

if(isset($_POST['davai'])) {
$file=$_POST['file'];
$current=fopen($file , "w");
echo "<form method='post'>";
echo "<textarea cols='60' rows='20' name='edit'>".stripslashes($current)."</textarea><br>";
echo "<input type='submit' name='submit' value='Save' action=".$_SERVER['PHP_SELF']."></form>";
if(isset($_POST['submit'])) {
$edited=$_POST['edit'];
$new=stripslashes($edited);
fwrite($file, $new);
fclose($current);
}
}
?>

Така ?
 
Код:
	  <?php
echo "Enter the directory and name of the file you wish to edit:<br>";
echo "<form method='post'>";
echo "<input type='text' name='file'><br>";
echo "<input type='submit' name='davai' value='Edit'><br><br></form>";

if(isset($_POST['davai'])) {
$file=$_POST['file'];
@ $current=file_get_contents($file);
echo "<form method='post'>";
echo "<textarea cols='60' rows='20' name='edit'>".stripslashes($current)."</textarea><br>";
echo "<input type='submit' name='submit' value='Save' action=".$_SERVER['PHP_SELF']."></form>";
if(isset($_POST['submit'])) {
$edited=$_POST['edit'];
$new=stripslashes($edited);
fwrite($file, $new);
fclose($current);
}
}
?>

Добре така ?
 
Код:
      <?php
echo "Enter the directory and name of the file you wish to edit:<br>";
echo "<form method='post' action=''>";
echo "<input type='text' name='file'><br>";
echo "<input type='submit' name='davai' value='Edit'><br><br></form>";

if(isset($_POST['davai'])) {
$file=$_POST['file'];
@ $current=file_get_contents($file);
echo "<form method='post' action=''>";
echo "<textarea cols='60' rows='20' name='edit'>".stripslashes($current)."</textarea><br>";
echo "<input type='submit' name='submit' value='Save'></form>";
if(isset($_POST['submit'])) {
$edited=$_POST['edit'];
$new=stripslashes($edited);
fwrite($file, $new);
fclose($current);
}
}
?>

Виш така ..
 
<?php
echo "Enter the directory and name of the file you wish to edit:<br>";
echo "<form method='post' action=''>";
echo "<input type='text' name='file'><br>";
echo "<input type='submit' name='davai' value='Edit'><br><br></form>";

if(isset($_POST['davai'])) {
$file=$_POST['file'];
echo "<form method='post' action=''>";
echo "<textarea cols='60' rows='20' name='edit'>".stripslashes($file)."</textarea><br>";
echo "<input type='submit' name='submit' value='Save'></form>";
if(isset($_POST['submit'])) {
$edited=$_POST['edit'];
file_put_contents($file, stripslashes($edited));
}
}
?>
Този е код е напълно безсмислен, незнам какво се опитваш да правиш
Пробвай, това което съм ти написал, но толкова е оплескан, че и аз се омотах
 
PHP_Masters каза:
baiumbg каза:
Пак не...

Ма я кажи дава ли ти ерор? или нещо просто не бачка, ако дава ерор дай да видим какво пише за да видим какво да редактираме

Не ми дава никакъв ерор. Просто нищо не прави.

emagi каза:
<?php
echo "Enter the directory and name of the file you wish to edit:<br>";
echo "<form method='post' action=''>";
echo "<input type='text' name='file'><br>";
echo "<input type='submit' name='davai' value='Edit'><br><br></form>";

if(isset($_POST['davai'])) {
$file=$_POST['file'];
echo "<form method='post' action=''>";
echo "<textarea cols='60' rows='20' name='edit'>".stripslashes($file)."</textarea><br>";
echo "<input type='submit' name='submit' value='Save'></form>";
if(isset($_POST['submit'])) {
$edited=$_POST['edit'];
file_put_contents($file, stripslashes($edited));
}
}
?>
Този е код е напълно безсмислен, незнам какво се опитваш да правиш
Пробвай, това което съм ти написал, но толкова е оплескан, че и аз се омотах

Кое си ми написал?
 
това в червено, което и аз ти сложих там в кода .. слагаш action не кадето трябва action трябва да е след method или преди тоест
<form method="POST" action="">
 
добре .. явно има нещо гнило .. ще ти предложа друго, ще направим всичко в отделни файлове, тоест формата и извеждането на файла в един файл и записването в друг .. да речем правиш си нов файл с име open.php и в него слагаш :

Код:
<form method="POST" action="">
File : <input type="text" name="file"><br />
<input type="submit" name="submit" value="go"></form>

<?php
if (isset($_POST['submit']))
{
$op=htmlspecialchars($_POST['file']);
$fp = fopen ("$op" ,"r");
$file= fread($fp,10000);
echo'<form method="post" action="edit.php" >
<TEXTAREA name="write" COLS=70 ROWS=15 > ';
echo $file;
echo
'</TEXTAREA> <br><br>
<INPUT TYPE=SUBMIT VALUE="Edit">
</FORM>';
}
?>

Така и сега edit.php, който реално ще редактира кода :

Код:
<?php
$text=$HTTP_POST_VARS['write'];
$file=$HTTP_POST_VARS['file'];
$text=stripslashes($text);
$fp = fopen ("$file" ,"w");
fwrite($fp, $text );
fclose($fp);
echo '
<center><b>Успешно редактирахте файла</b></center>
';
?>

така би трябвало да стане
 
объркал си последователноста и онаследяването на данните

така работи

Код:
<?php
print_r($_POST);

echo "Enter the directory and name of the file you wish to edit:<br>";
echo "<form method='post'>";
echo "<input type='text' name='files'><br>";
echo "<input type='submit' name='davai' value='Edit'><br><br></form>";

if(isset($_POST['davai'])) {
$file=$_POST['files'];
$current=file_get_contents($file);
echo "<form method='post'>";
echo "<textarea cols='60' rows='20' name='edit'>".stripslashes($current)."</textarea><br>";
echo "<input type='hidden' name='files' value='". $file ."'>";
echo "<input type='submit' name='submit' value='Save' action=".$_SERVER['PHP_SELF']."></form>";

}


if(isset($_POST['submit'])) {
$edited=$_POST['edit'];
$file=$_POST['files'];
echo "$edited | $files ";
	file_put_contents($files, stripslashes($edited));
}

?>
 
amana каза:
объркал си последователноста и онаследяването на данните

така работи

Код:
<?php
print_r($_POST);

echo "Enter the directory and name of the file you wish to edit:<br>";
echo "<form method='post'>";
echo "<input type='text' name='files'><br>";
echo "<input type='submit' name='davai' value='Edit'><br><br></form>";

if(isset($_POST['davai'])) {
$file=$_POST['files'];
$current=file_get_contents($file);
echo "<form method='post'>";
echo "<textarea cols='60' rows='20' name='edit'>".stripslashes($current)."</textarea><br>";
echo "<input type='hidden' name='files' value='". $file ."'>";
echo "<input type='submit' name='submit' value='Save' action=".$_SERVER['PHP_SELF']."></form>";

}


if(isset($_POST['submit'])) {
$edited=$_POST['edit'];
$file=$_POST['files'];
echo "$edited | $files ";
	file_put_contents($files, stripslashes($edited));
}

?>

Пак не работи. Обаче изкарва Warning:

Warning: file_put_contents() [function.file-put-contents]: Filename cannot be empty in /home/*******/public_html/test/edit.php on line 24
 
хм - при мен точно този код работи

пробвай да с това

Код:
<?php

foreach( $_POST as $key => $value )
        $$key = $value;
foreach( $_GET as $key => $value )
        $$key = $value;
foreach( $_COOKIE as $key => $value )
        $$key = $value;


print_r($_POST);

echo "Enter the directory and name of the file you wish to edit:<br>";
echo "<form method='post'>";
echo "<input type='text' name='files'><br>";
echo "<input type='submit' name='davai' value='Edit'><br><br></form>";

if(isset($_POST['davai'])) {
$file=$_POST['files'];
$current=file_get_contents($file);
echo "<form method='post'>";
echo "<textarea cols='60' rows='20' name='edit'>".stripslashes($current)."</textarea><br>";
echo "<input type='hidden' name='files' value='". $file ."'>";
echo "<input type='submit' name='submit' value='Save' action=".$_SERVER['PHP_SELF']."></form>";

}


if(isset($_POST['submit'])) {
$edited=$_POST['edit'];
$file=$_POST['files'];
echo "$edited | $files ";
   file_put_contents($files, stripslashes($edited));
}

?>
 
Добре пробвай моя код .. той със сигорност си работи .. аз ползвам този код .. нищо, че е в два файла по чисто направено е така ..
 
amana каза:
хм - при мен точно този код работи

пробвай да с това

Код:
<?php

foreach( $_POST as $key => $value )
        $$key = $value;
foreach( $_GET as $key => $value )
        $$key = $value;
foreach( $_COOKIE as $key => $value )
        $$key = $value;


print_r($_POST);

echo "Enter the directory and name of the file you wish to edit:<br>";
echo "<form method='post'>";
echo "<input type='text' name='files'><br>";
echo "<input type='submit' name='davai' value='Edit'><br><br></form>";

if(isset($_POST['davai'])) {
$file=$_POST['files'];
$current=file_get_contents($file);
echo "<form method='post'>";
echo "<textarea cols='60' rows='20' name='edit'>".stripslashes($current)."</textarea><br>";
echo "<input type='hidden' name='files' value='". $file ."'>";
echo "<input type='submit' name='submit' value='Save' action=".$_SERVER['PHP_SELF']."></form>";

}


if(isset($_POST['submit'])) {
$edited=$_POST['edit'];
$file=$_POST['files'];
echo "$edited | $files ";
   file_put_contents($files, stripslashes($edited));
}

?>

Стана :) Мерси много. justspy предпочитам да е от 1 файл, защото не обичам да права 1000 файла...
 

Back
Горе