开发者

fwrite in php not working in binary mode

开发者 https://www.devze.com 2023-03-01 09:33 出处:网络
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:

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

精彩评论

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