سؤال

I'm trying to write in a txt file the data i get from a html form, but I get this error: Warning: fopen(/var/www/4/datos.txt): failed to open stream: Permission denied in /var/www/4/ComprobacionFormulario.php on line 13 Warning: fwrite() expects parameter 1 to be resource, boolean given in /var/www/4/ComprobacionFormulario.php on line 16 Warning: fclose() expects parameter 1 to be resource, boolean given in /var/www/4/ComprobacionFormulario.php on line 17

'datos.txt' Is the file where i'm trying to write. Here is my php code:

error_reporting(E_ALL);
ini_set('display_errors', true);

$des=$_POST['description'];
$cant=$_POST['quantity'];
$prec=$_POST['price'];
$nombrearchivo="datos.txt";
$content="Description: $des\tQuantity: $cant\tPrice: $prec\n";
$handle=fopen($nombrearchivo, 'w');

fwrite($handle, $content);
fclose($handle);
هل كانت مفيدة؟

المحلول

From the manual: [fopen] Returns a file pointer resource on success, or FALSE on error.

Looks like your fopen call is failing. Try using an absolute URL to your text file. Make sure your folder is CHMODded correctly and the file also (777 permissions)

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top