Sunucusundan indirilen. Exe dosya bozuluyor

2 Cevap php

Birincisi: Ben tehlikeli olmaya yeterli PHP bilen ve, iyi, bir şey olmak için sunucu yönetimi hakkında yeterli bir asılıyor web tasarımcısı değilim. Eğer çok açık olmadıkça ben muhtemelen seni anlamak olmaz!

Kurulum: Ben müşteri belirli bir dizine dosyaları yükler ve bu dosyaların kullanıcılar tarafından indirilebilir, php, hazır bir web sitesi kurdum. Dosyaları 50MB üzerinde genellikle çalıştırılabilir dosyalardır. Onların kullanıcılar bunları halletmek için yeterli anlayışlı değildir hissediyorum gibi istemci, onları sıkıştırılmış istemiyor. Ben bir indirme diyalog kutusu zorlamak ve dosyalarının bulunduğu dizini gizlemek için aşağıdaki php kullanıyorum.

Bir fark yapar eğer, Linux sunucu var.

Sorun: kullanıcı indirmek için çalışır, sonra bozuk olur belli bir dosya vardır. Bu bir yürütülebilir dosya, ancak tıklandığında olduğunda, boş bir DOS penceresi açılır. Önce indirmek için orijinal dosya, mükemmel açılır. Orada aynı tam indirme işleminden geçmesi birkaç diğer benzer dosyaları vardır ve bunların hepsi sadece iyi çalışır.

Things I've tried: I've tried uploading the file zipped, then unzipping it on the server to make sure it wasn't becoming corrupt during upload, and no luck.
I've also compared the binary code of the original file to the downloaded file that doesn't work, and they're exactly the same (so the php isn't accidentally inserting anything extra into the file).

Benim DownloadFile işlevi başlıkları ile bir sorun olabilir mi? Ben gerçekten bu bir gidermek için nasıl emin değilim ...

O ($ filenamereplace yerde tanımlanır) alakalı eğer bu, yükleme php:

downloadFile("../DIRECTORY/files/$filenamereplace","$filenamereplace");

function downloadFile($file,$filename){    
    if(file_exists($file)) {
        header('Content-Description: File Transfer');
        header('Content-Type: application/octet-stream');
        header('Content-Disposition: attachment; filename="'.$filename.'"');
        header('Content-Transfer-Encoding: binary');
        header('Expires: 0');
        header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
        header('Pragma: public');
        header('Content-Length: ' . filesize($file));
        @ flush();
        readfile($file);
        exit;
    }
}

ETA Additonal Info: - Tests for working/non-working files have been done on the same machine - If it makes any difference, the original file has a custom icon. After download, the file has a generic blank document icon.

Additonal Info: I THINK THIS ONE'S IMPORTANT! I just tried downloading the file directly (to bypass the download link that triggers the download function above). If I download the file by just going to its url and downloading it that way, the downloaded file WORKS. So I'm thinking it must have something to do with the download function. But what??

3/17 MAJOR CORRECTION —AND RESOLVED— So I woke up this morning and it dawned on me that maybe I was comparing the files wrong. (I had re-saved them as binary text, and then compared them. I didn't realize the comparison program would take and compare actual exe files). This morning I tried comparing the actual exe files and there is a difference. There was one line of php code that was being injected into the first line of the file. I adjusted the php, and the problem was fixed. (It was from the if/else statement that defined teh $filenamereplace variable in the code I'd cited). Thanks again for all your help, and sorry for misleading you in insisting that the files' contents were identical!

2 Cevap

"Ben de işe yaramazsa indirilen dosya için orijinal dosyanın ikili kodunu karşılaştırıldı ve bunların tam olarak aynı (yani php yanlışlıkla dosyaya ekstra bir şey ekleme değildir). Ettik"

Bu gerçekten doğru ise, o zaman sorun indirildikten sonra exe başladı nasıl olmalıdır. Bu kesinlikle PHP kodu ile ilgili bir sorun olmamalı.

Belki de upload bozulmuş idi. Yerine BINARY ASCII modunda FTP yoluyla aktarmak, bu durum oluşabilir.