I'm getting this error: Warning: fwrite(): supplied argument is not a valid stream resource in / mypath on line 1222
My code is this: - $File = "custom.css";
-
$Handle = fopen($File, 'w') or die("can't open file");
-
if (fwrite($Handle, $css_file) === FALSE)
-
{
-
echo "Cannot write to file ($File)";
-
exit;
-
}
The error text also appears below the error. The CHMOD on the directory is 777.
Am I overlooking somethng?
6 2085 Atli 5,058
Expert 4TB
Hey.
Are you sure those are the correct lines from the code?
I ask because the fopen function either returns a stream resource, which would not cause this error, or it returns FALSE, which in your code would trigger the or die command.
This error shouldn't be possible using that code.
To be sure, thought, try printing the contents of the $Handle before the fwrite just to see exactly what it is: - <?php
-
$File = "custom.css";
-
$Handle = fopen($File, 'w') or die("can't open file");
-
-
var_dump($Handle); exit;
-
-
if (fwrite($Handle, $css_file) === FALSE)
-
{
-
echo "Cannot write to file ($File)";
-
exit;
-
}
-
?>
I will try that out. Line 1222 is:
if (fwrite($Handle, $css_file) === FALSE)
I'll find out what's in the Handle.
When using the var dump it gives me:
resource(53) of type (stream)
I'm afraid I don't understand what this means. It it supposed to show something else?
It's working now. All I did was add the code you suggested, looked at the error message and took the code out and tired it again and it's working.
I'm glad it's working but I'd like to know why.
Thanks for your help.
Atli 5,058
Expert 4TB
Hmm... odd.
Did you copy the original code from somewhere? Like a web-page?
It is possible that there was a "special" character in there, invisible, which PHP took as a part of the variable name... Or just some odd charset mismatch.
I can't remember. I think I copied the code from php.net. I would have thought there wouldn't be any invisible characters there.
The only think that worries me is that if it didn't work and them for seemingly no reason starts to work, I hope it doens't later on stop with no warning.
Thanks for all youe help.
Sign in to post your reply or Sign up for a free account.
Similar topics
by: Tuuska |
last post by:
Hello!
I have this problem, when fwrite() writes to the beginning of xyz.txt
file, it overwrites the first line. Any ideas how to prevent this? I'm
running PHP 4.3.3RC3 on Linux.
<?php
$fp =...
|
by: Martin Lucas-Smith |
last post by:
I wrote the function below as part of a larger class.
The fopen stage works, and, as according to the documentation at
www.php.net/fopen that succesfully creates a new file.
The fwrite stage...
|
by: Bob Bedford |
last post by:
I'm trying to save an XML file sent to me in ZIP format.
Here is the code:
if($XMLFile=fopen($XMLPath.strtoupper(substr($file,0,strlen($file)-4)).".XML",'w'))...
|
by: Brady |
last post by:
Hi,
I'm having a problem reading and writing to a file. What I'm trying
to do is read a file, modify the portion of the file that I just read,
and then write the modified data back to the same...
|
by: FrancisC |
last post by:
how to use fwrite( ) instead of fprintf( ) in this case? I want to generate
binary file.
FILE *fnew;
int i, intName;
double array;
fprintf(fnew, "%d\n", intName);...
|
by: cs |
last post by:
if i have
typedef struct{
unsigned a;
unsigned *b;
}tp;
i would like to ask if it is ok for the "C standard 89" doing
something like this
{
|
by: janssenssimon |
last post by:
//de structure om de highscores in op de slagen
typedef struct score{
char *naam;
int veld;
int score;
struct score *volg;
}HIGH;
void toonhighscores(void)
|
by: Richard Hsu |
last post by:
// code
#include "stdio.h"
int status(FILE * f) {
printf("ftell:%d, feof:%s\n", ftell(f), feof(f) != 0 ? "true" :
"false");
}
int case1() {
FILE * f = fopen("c:\\blah", "wb+");
int i = 5;
|
by: David Mathog |
last post by:
In the beginning (Kernighan & Ritchie 1978) there was fprintf, and unix
write, but no fwrite. That is, no portable C method for writing binary
data, only system calls which were OS specific. At...
|
by: miraan |
last post by:
Hi, I am trying to create a script that creates other php scripts but I am getting a problem, when I create the file and use fwrite() to write to it, it returns an error saying: Parse error: syntax...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: ryjfgjl |
last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
| |