Simple text file creation fails....

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
folken7182
Forum Newbie
Posts: 2
Joined: Sun Apr 17, 2005 4:51 pm
Location: Queretaro Mexico
Contact:

Simple text file creation fails....

Post by folken7182 »

Hello guys and girls... I have a problem trying to create a simple text file... it doesn't want to be created... It just return that can't write or can't be created..

I have tried with the example of fwrite from http://www.php.net and even that example fails...

Code: Select all

<?php
$nombre_archivo = 'prueba.txt';
$contenido = "Agregar esto al archivo\n";


if (is_writable($nombre_archivo)) {

	if (!$gestor = fopen("$nombre_archivo", 'a')) {
		echo "No se puede abrir el archivo ($nombre_archivo)";
		exit;
	}


	if (fwrite($gestor, $contenido) === FALSE) {
		echo "No se puede escribir al archivo ($nombre_archivo)";
		exit;
	}

	echo "&Eacute;xito, se escribi&oacute; ($contenido) al archivo ($nombre_archivo)";

	fclose($gestor);

} 
else {
	echo "No se puede escribir sobre el archivo $nombre_archivo";
}
?>
hongco
Forum Contributor
Posts: 186
Joined: Sun Feb 20, 2005 2:49 pm

Post by hongco »

have you chmod the folder to 777 where the file should be saved at?
User avatar
folken7182
Forum Newbie
Posts: 2
Joined: Sun Apr 17, 2005 4:51 pm
Location: Queretaro Mexico
Contact:

Post by folken7182 »

I am working in Windows, Using xampp I don't know if I need permissions
Post Reply