Why fopen 1st Parameter Does Not Work ?

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
UniqueIdeaMan
Forum Contributor
Posts: 197
Joined: Wed Jan 18, 2017 3:43 pm

Why fopen 1st Parameter Does Not Work ?

Post by UniqueIdeaMan »

Fellow Programmers,

The following codes are supposed to creates 4 different files:

1.

Code: Select all


<?php

$ourFileName = "testFile_1.txt";
$ourFileHandle = fopen($ourFileName, 'w') or die("can't open file");
fclose($ourFileHandle);

?>


2.

Code: Select all


<?php

$ourFileName = "testFile_2.txt";
$ourFileHandle = fopen($ourFileName, 'w') or die("can't open file");
fclose($ourFileName);

?>


3.

Code: Select all


<?php

$ourFileHandle = fopen(testFile_3.txt, 'w') or die("can't open file");
fclose($ourFileHandle);

?>


4.

Code: Select all


<?php

fopen(testFile_4.txt, 'w') or die("can't open file");
fclose(testFile_4.txt);

?>


But why does the last 2 create files without the "." (dot) extension ?

Also, I have numbered all my 4 codes 1, 2, 3 & 4 but the thread shows all 4 codes numbered the same. Chrome and Fire Fox shows this.
Made a clip to demonstrate the issue. How can I send it to mods since this attachment refuses to upload video clips ?
Last edited by UniqueIdeaMan on Sun Jun 18, 2017 7:21 pm, edited 2 times in total.
User avatar
Christopher
Site Administrator
Posts: 13596
Joined: Wed Aug 25, 2004 7:54 pm
Location: New York, NY, US

Re: Why fopen 1st Parameter Does Not Work ?

Post by Christopher »

The file names change. Is it possible you can open an existing file for writing, but not create new files?
(#10850)
User avatar
Pazuzu156
Forum Contributor
Posts: 241
Joined: Sat Nov 20, 2010 9:00 pm
Location: GA, USA
Contact:

Re: Why fopen 1st Parameter Does Not Work ?

Post by Pazuzu156 »

Also, you're forgetting to use quotes around the filenames in 3 and 4
- Kaleb Klein
------------------------------------
Web Developer | Software Developer
https://kalebklein.com
PGP Key: https://keybase.io/pazuzu156
Post Reply