Php kullanarak .docx dosyasını sunmaya çalışırken sorunlar yaşıyorum. Dosyayı yüklerken mime tipini tespit ettim ve dosyayı mime tipine göre doğru uzantıyı kullanarak yükledim; Örneğin. Aşağıda:Php aracılığıyla .docx dosyaları sunuluyor
application/msword - doc
application/vnd.openxmlformats-officedocument.wordprocessingml.document - docx
indirmek için dosyaları hizmet çalışırken, ben uzantısı algılama ve mim türü örn dayalı sunumunun içinde ters yapmak
public static function fileMimeType($extention) {
if(!is_null($extention)) {
switch($extention) {
case 'txt':
return 'text/plain';
break;
case 'odt':
return 'application/vnd.oasis.opendocument.text';
break;
case 'doc':
return 'application/msword';
break;
case 'docx':
return 'application/vnd.openxmlformats-officedocument.wordprocessingml.document';
break;
case 'jpg':
return 'image/jpeg';
break;
case 'png':
return 'image/png';
break;
case 'pdf':
return 'application/pdf';
break;
default:
break;
}
}
}
tüm dosyaların doğru ve açık ceza indirmek için görünür, ancak (birden çok dosya üzerinde) bir docx dosyasını Word açmaya çalışırken dosya bozuk belirten bir hata atar.
Herhangi bir fikir harika olurdu, teşekkürler.
Düzenleme # 1
try {
$file = new Booking_Document((int)$get_data['bookingDocument']);
header('Content-Type: ' . Booking_Document::fileMimeType($file->getDocumentType()));
header('Content-Disposition: attachment; filename=' . $file);
header('Expires: 0');
header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
header('Pragma: public');
echo readfile(Zend_Registry::get(static::$_uploadDir).$this->_id);
} catch (Exception $e) {
View_Helpers_FlashMessages::addMessage(array('message' => $e->getMessage(), 'type' => 'error'));
}
exit;
SABİT
readfile çağırmadan önce() Ben ob_clean eklendi() ve gömme() sorunu düzelttikten göründüğü.
'case ('jpg' || 'jpeg'):' çalışmaz, 'case' jpg 'yazmanız gerekir: case' jpeg ': '. – deceze
Benzer soru, yardımcı olabilir: http://stackoverflow.com/questions/179315/downloading-docx-from-ie-setting-mime-types-in-iis – kapa
İstemci tarafında aldığınız sonuç nedir? Diske kaydedildiğinde geçerli bir dosya mı? – deceze