Jump to content

Check file


paulman888888

Recommended Posts

This is my code!

<?php

$ourFileName = "games/{$_POST['name']}.php"; // the name of the file to be made
$ourFileHandle = fopen($ourFileName, 'w') or die("Can't make file");
fclose($ourFileHandle);

$myFile = "games/{$_POST['name']}.php";
$fh = fopen($myFile, 'w') or die("There's an error!");
$stringData = "$_POST[main].php";
fwrite($fh, $stringData);
fclose($fh);

?>

 

I would like something to check if the file name already exists.

Can someone please help.

 

Thankyou

 

Link to comment
https://forums.phpfreaks.com/topic/106511-check-file/
Share on other sites

is this right?

<?php
$filename = "games/{$_POST['name']}.php";

if (file_exists($filename)) {
    echo "Theres an error. That file already exists. Go back and change the name of the game.";
} else {
    $ourFileName = "games/{$_POST['name']}.php";
$ourFileHandle = fopen($ourFileName, 'w') or die("Can't make file");
fclose($ourFileHandle);

$myFile = "games/{$_POST['name']}.php";
$fh = fopen($myFile, 'w') or die("There's an error!");
$stringData = "$_POST['main'].php";
fwrite($fh, $stringData);
fclose($fh);
}
?>

 

thankyou

 

Link to comment
https://forums.phpfreaks.com/topic/106511-check-file/#findComment-545984
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.