2014-10-18 8 views
6

मेरे प्रणाली अगले फ़ाइलें और सबफ़ोल्डरपिन php सामान्य इनपुट/आउटपुट त्रुटि का उपयोग कर

enter image description here

मैं एक odt फ़ाइल बनाने के लिए this code उपयोग कर रहा हूँ के साथ एक फ़ोल्डर उत्पन्न ODT फ़ाइल बनाएँ। जब मैं इस कोड का उपयोग करके अपने सिस्टम को चलाता हूं तो उस सबफ़ोल्डर और फ़ाइलों को अपाचे + PHP और उबंटू 12.04 पर test.odt फ़ाइल में ज़िप करने के लिए ओडीटी फ़ाइल ठीक है। लेकिन जब मैं IIS + PHP और Windows पर test.odt फ़ाइल में ज़िप करने का प्रयास करता हूं तो odt फ़ाइल काम नहीं करती है। मुझे काम नहीं पता है क्योंकि जब मैं लिबर ऑफिस के साथ ओडीटी फ़ाइल खोलता हूं तो मुझे त्रुटि इनपुट/आउटपुट सामान्य त्रुटि मिलती है।Here ओडीटी फ़ाइल।

जब मैं विंडोज़ पर उत्पन्न ओडीटी फ़ाइल निकालने के लिए फ़ोल्डरों और फ़ाइलों में चित्र का एक ही रूप होता है। मैं Google में देख रहा हूं और शायद समस्या एक mimetype एन्कोडिंग है।

मैं कोड 1 कोड को कैसे संशोधित कर पाऊंगा ताकि मुझे मेरी समस्या ठीक हो जाए?

संपादित

मैं नीचे दिए गए कोड के साथ this folder का उपयोग, लेकिन मैं केवल मिल "PKÜNTEBasic/PKÜNTEú ミ, LOR/बेसिक/लिपि-lc.xmle マ AoÂ0" मेरे odt फ़ाइल में। Here the example

<?php 

$wordtemplatedownloadpath="siscons\\test\\wordtemplatedownload\\"; 
Zip($wordtemplatedownloadpath."pasta3", $wordtemplatedownloadpath."test.odt"); 
force_download("test.odt", $wordtemplatedownloadpath."test.odt"); 
//echo "<a href=test/wordtemplatedownload/test.odt>" . "Download Force". "</a>"; 
function Zip($source, $destination) 
{ 
    if (!extension_loaded('zip') || !file_exists($source)) { 
    return false; 
    } 

$zip = new ZipArchive(); 
if (!$zip->open($destination, ZIPARCHIVE::CREATE)) { 
    return false; 
} 

$source = str_replace('\\', '/', realpath($source)); 
//echo $source; 
if (is_dir($source) === true) 
{ 
    $files = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($source), RecursiveIteratorIterator::SELF_FIRST); 

    foreach ($files as $file) 
    { 
     //print "file#".$file."\n"; 
     $file = str_replace('\\', '/', $file); 

     // Ignore "." and ".." folders 
     if(in_array(substr($file, strrpos($file, '/')+1), array('.', '..'))) 
      continue; 

     //$file = realpath($file); 
     //print "file#".$file."\n"; 
     if (is_dir($file) === true) 
     { 
      //$zip->addEmptyDir(str_replace($source . '/', '', $file . '/')); 
      //echo "sourcE".$source."FilE".$file."ReplacE".str_replace($source . '/', '', $file)."End"; 
      $zip->addEmptyDir(str_replace($source . '/', '', $file)); 
     } 
     else if (is_file($file) === true) 
     { 

      $str1 = str_replace($source . '/', '', '/'.$file); 
      $str1 = str_replace('/', '/', $str1); 
      $zip->addFromString($str1, file_get_contents($file)); 
      //$zip->addFromString("subfolder/styles.xml", file_get_contents($file)); 

     } 
    } 
} 
else if (is_file($source) === true) 
{ 
    $zip->addFromString(basename($source), file_get_contents($source)); 
} 

return $zip->close(); 
} 

function force_download($filename = '', $data = '') 
{ 
    if($filename == '' || $data == ''){ 
    return false; 
    } 

    if(!file_exists($data)) 
    { 
    return false; 
    } 

// Try to determine if the filename includes a file extension. 
// We need it in order to set the MIME type 
if(false === strpos($filename, '.')) 
{ 
    return false; 
} 

// Grab the file extension 
$extension = strtolower(pathinfo(basename($filename), PATHINFO_EXTENSION)); 

// our list of mime types 
$mime_types = array(

    'txt' => 'text/plain', 
    'htm' => 'text/html', 
    'html' => 'text/html', 
    'php' => 'text/html', 
    'css' => 'text/css', 
    'js' => 'application/javascript', 
    'json' => 'application/json', 
    'xml' => 'application/xml', 
    'swf' => 'application/x-shockwave-flash', 
    'flv' => 'video/x-flv', 

    // images 
    'png' => 'image/png', 
    'jpe' => 'image/jpeg', 
    'jpeg' => 'image/jpeg', 
    'jpg' => 'image/jpeg', 
    'gif' => 'image/gif', 
    'bmp' => 'image/bmp', 
    'ico' => 'image/vnd.microsoft.icon', 
    'tiff' => 'image/tiff', 
    'tif' => 'image/tiff', 
    'svg' => 'image/svg+xml', 
    'svgz' => 'image/svg+xml', 

    // archives 
    'zip' => 'application/zip', 
    'rar' => 'application/x-rar-compressed', 
    'exe' => 'application/x-msdownload', 
    'msi' => 'application/x-msdownload', 
    'cab' => 'application/vnd.ms-cab-compressed', 

    // audio/video 
    'mp3' => 'audio/mpeg', 
    'qt' => 'video/quicktime', 
    'mov' => 'video/quicktime', 
    // adobe 
    'pdf' => 'application/pdf', 
    'psd' => 'image/vnd.adobe.photoshop', 
    'ai' => 'application/postscript', 
    'eps' => 'application/postscript', 
    'ps' => 'application/postscript', 

    // ms office 
    'doc' => 'application/msword', 
    'rtf' => 'application/rtf', 
    'xls' => 'application/vnd.ms-excel', 
    'ppt' => 'application/vnd.ms-powerpoint', 

    // open office 
    'odt' => 'application/vnd.oasis.opendocument.text', 
    'ods' => 'application/vnd.oasis.opendocument.spreadsheet', 
); 

// Set a default mime if we can't find it 
if(!isset($mime_types[$extension])) 
{ 
    $mime = 'application/octet-stream'; 
} 
else 
{ 
    $mime = (is_array($mime_types[$extension])) ? $mime_types[$extension][0] : $mime_types[$extension]; 
} 

// Generate the server headers 
if(strstr($_SERVER['HTTP_USER_AGENT'], "MSIE")) 
{ 
    header('Content-Type: "'.$mime.'"'); 
    header('Content-Disposition: attachment; filename="'.$filename.'"'); 
    header('Expires: 0'); 
    header('Cache-Control: must-revalidate, post-check=0, pre-check=0'); 
    header("Content-Transfer-Encoding: binary"); 
    header('Pragma: public'); 
    header("Content-Length: ".filesize($data)); 
} 
else 
{ 
    header("Pragma: public"); 
    header("Expires: 0"); 
    header("Cache-Control: must-revalidate, post-check=0, pre-check=0"); 
    header("Cache-Control: private", false); 
    header("Content-Type: ".$mime, true, 200); 
    header('Content-Length: '.filesize($data)); 
     header('Content-Disposition: attachment; filename='.$filename); 
     header("Content-Transfer-Encoding: binary"); 
    } 
    readfile($data); 
    exit; 

} //End force_download 
?> 
+2

कृपया प्राप्त त्रुटि और एक प्रभावित ओडीटी फ़ाइल डाउनलोड करने के लिए एक लिंक जोड़ें। धन्यवाद। – dotancohen

+0

मैंने आपके प्रश्नों को आपके सुझावों के साथ संपादित किया। – Juan

+0

मैं पीसीएलजेआईपी और http://www.phpconcept.net/pclzip/faq का Q5 का उपयोग करता हूं और मेरी स्क्रिप्ट अब काम करती है! – Juan

उत्तर

संबंधित मुद्दे