开发者

fwrite in php not working in binary mode

I am a .net guy and have got a code which works on one of our servers but not on the other, not even on my local machine. The code snippet is given below:

//$flocal1 = fopen($MVfile_name.".txt", "w");
//开发者_StackOverflow中文版@fwrite($flocal1, "my name is gaurav pandey!!!");
//opening file
$flocal = fopen($MVfile_name, $mode);

//writing to file

if (!(@fwrite($flocal, $contents))) 
{

//writing error if writing operation failed

  exit(NotUpload);

}

//closing file fclose($flocal);

As we can see, I tried same code with writing a text file with a string and that worked fine, but with binary files, I am getting the error.


If you're on a Windows server, use the b flag to fopen.

fopen($filename, 'wb');

This should already by set by PHP according to the manual, but maybe you are on an old server where this isn't the case.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜