0

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");
//@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.

1 Answer 1

1

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.

Sign up to request clarification or add additional context in comments.

3 Comments

But then how this code is working fine on some other machines? I am not able to understand.
You question does not contain enough info to help here. Which charset is the file saved as? How do you know $flocal is the correct value? What are you trying to do?
Actually I am using a webcam recorder and it posts the value to my php file, the file stream is of type .mp4. $flocal might be the correct value as the file is created first time here and the file stream is being written into it.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.