Viewing 9 replies - 1 through 9 (of 9 total)
  • Thread Starter mewersthecat

    (@mewersthecat)

    I resolved my own issue…

    The cause the octet stream was being downloaded with an automatic BOM at the beginning which was corrupting my files.

    I’m not a PHP guy so it took a little work.. I made sure my PHP files were being saved as utf8 without BOM, and still no luck,
    I edited CF7DBPlugin.php and made sure to call ob_clean() before calling the header information in the ajaxFile function., and that resolved my issue.. I’m not sure if there’s a more elegant solution or not..

    Plugin Author Michael Simpson

    (@msimpson)

    Exports for Excel are supposed to have a BOM so that they are read correctly on Windows. If you use Excel on Mac then you should use the Plain CSV export to avoid getting the BOM. If importing into any other spreadsheet, use Plain CSV.

    Thread Starter mewersthecat

    (@mewersthecat)

    I’m not talking about Exporting to Excel, I’m talking about downloading files that users uploaded via the Contact Form.

    I had the latest version of everything, Contact Form DB, Contact Form 7 and WordPress.. but if I uploaded, say… a zip file, then clicked on the file name, save it to my harddrive, then try to open it.. it would be corrupt and not open properly…..
    The cause being, the first 3 bytes of the file were the BOM, which corrupted the entire thing.

    I’m not sure if the actual cause was some… apache/nginx module.. As I was developing on some.. bluehost shared hosting service.. or what.. but.. I fixed it by adding the ob_clean() at the begining of the ajaxFile function.

    Plugin Author Michael Simpson

    (@msimpson)

    I can’t reproduce the issue. The ajaxFile() function is called directly from the WordPress ajax hook and you can see in the code, it write 1 or 2 headers then just outputs the file’s contents. It seems to me that something else is injecting the characters.

    Thread Starter mewersthecat

    (@mewersthecat)

    Right.. I assumed something like that would be hard to reproduce considering, the problem would come up pretty fast (not being able to download files that aren’t… text based)

    Thanks for your help, I’m really not sure of the cause of my BOM problem.. but i guess that’s irrelevant now. I’m sure some module on the shared webserver is writing the BOM to the response stream before executing the PHP file.

    Have a good day!

    Plugin Author Michael Simpson

    (@msimpson)

    I’m pushing version 2.9.10 with a fix based on this thread.

    I still have the problem with downloading of corrupted files. Tried only with .doc files, but I think the same will be with onthers. If I open downloaded from CFDB file in Word, it is corrupted. I thried then to open downloaded file with Notepad++ and save it as UTF-8 without BOM. After this the file was opened fine with Word.
    I tried to modify ajaxFile() like you tell, but this didn`t work for me.
    Can you tell me where I should place the fixing string? And what exactly its` content?

    UPDATE

    May be CFDB is corrupting files when saves it into db?

    Ok, I was experimenting for about 30 minutes, and found the fix for my case.
    I replaced your 512-514 lines (of CF7DBPlugin.php)

    if (ob_get_contents()) {
      ob_clean(); // Fix bug where download files can be corrupted
    }

    with next lines

    while (ob_get_level()) {
      ob_end_clean();
    }

    Notice, I had to remove if (ob_get_contents()) statement, because with it the file remained corrupted.

    Plugin Author Michael Simpson

    (@msimpson)

    Ok, I’ll push that change out. Thanks for looking into it.

Viewing 9 replies - 1 through 9 (of 9 total)
  • The topic ‘Files are corrupt’ is closed to new replies.