File not found

Topics: Developer Forum, User Forum
Jun 17, 2013 at 8:48 AM
Hello,
I have a problem and hope, somone can help me... I create a EXCEL-File with PHP, save it then and send it to the browser. When I do this at home with xampp everything works fine. If I do this with my WebServer I receive the message "File not found" - or in German:

Fehler: Datei nicht gefunden
Die Dateien unter http://..../tagesplan_gesamt.php?Datum=03.06.2013&OK=OK konnten nicht gefunden werden.

Here is the code:
<?php

// Header für Browser-Output
header('Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet');
header('Content-Disposition: attachment;filename="Tagesplan-Maschine.xlsx"');
header('Cache-Control: max-age=0');

// Einpflegen der Excel-Klassen
require_once ("../classes/PHPExcel.php");

// Neues Objekt erstellen
$objPHPExcel = new PHPExcel();

// Eigenschafen des Dokuments
$objPHPExcel->getProperties()->setCreator("HeliBlog 2.0")
                             ->setLastModifiedBy("HeliBlog 2.0")
                             ->setTitle("Tagesplan nach Immatrikulation")
                             ->setSubject("Tagesplan $Immatrikulation")
                             ->setDescription("Tagesplan nach Maschine HeliBlog 2.0")
                             ->setKeywords("Tagesplan Immatrikulation Maschine")
                             ->setCategory("Tagesplan");


// Ausgabeformat auf DIN A4 festlegen
$objPHPExcel->getActiveSheet()->getPageSetup()->setOrientation(PHPExcel_Worksheet_PageSetup::ORIENTATION_PORTRAIT);
$objPHPExcel->getActiveSheet()->getPageSetup()->setPaperSize(PHPExcel_Worksheet_PageSetup::PAPERSIZE_A4);

// Alles an eine Seite anpassen, solange keine Breaks definiert sind
$objPHPExcel->getActiveSheet()->getPageSetup()->setFitToPage(false);
$objPHPExcel->getActiveSheet()->getPageSetup()->setFitToWidth(1);
$objPHPExcel->getActiveSheet()->getPageSetup()->setFitToHeight(25);

// Tabelle auswählen
$objPHPExcel->setActiveSheetIndex(0);

// Header und Footer 
$objPHPExcel->getActiveSheet()->getHeaderFooter()->setOddHeader('&CEinsatzplan für den '.$_GET["Datum"].' - '.$_GET["Immatrikulation"]);
$objPHPExcel->getActiveSheet()->getHeaderFooter()->setOddFooter('&L&B' . $objPHPExcel->getProperties()->getTitle() . '&RSeite &P von &N');

// Spaltenbreiten einstellen
$objPHPExcel->getActiveSheet()->getColumnDimension('A')->setWidth(20);
$objPHPExcel->getActiveSheet()->getColumnDimension('B')->setWidth(50);

// Zelleninhalte immer links - oben
$objPHPExcel->getActiveSheet()->getStyle('A')->getAlignment()->setVertical(PHPExcel_Style_Alignment::VERTICAL_TOP);

// Zeilenumbrüche für die Spalte B
$objPHPExcel->getActiveSheet()->getStyle('B')->getAlignment()->setWrapText(true);

// Überschriften definieren
$styleArray_Font_Ueb1 = array( 'font' => array( 'name' => 'Arial', 'size' => '12' ) ); 
$styleArray_Font_Ueb2 = array( 'font' => array( 'name' => 'Arial', 'size' => '11' ) ); 
$styleArray_Font_Ueb3 = array( 'font' => array( 'name' => 'Arial', 'size' => '10' ) ); 


// Beginn der Schleife
$Datum = date_german2mysql($_GET["Datum"]);

$query = "SELECT * FROM flugplanung WHERE Flugdatum = '$Datum' AND Immatrikulation = '$Immatrikulation' ORDER BY Von, Crew_1";
$result = mysql_query($query) or die(mysql_error());

// Startpositionen
$c = 0; $r = 1;
$counter = 0;

while($row = mysql_fetch_array($result)) {

    // #################### Beginn des Blocks ####################

    // Zähler
    $counter++;
    
    if($counter == 1) { $r++; }
    
    // Zeile 1 - Einfärben
    $default_border = array(
        'style' => PHPExcel_Style_Border::BORDER_THIN,
        'color' => array('rgb'=>'CCCCCC')
    );

    $style_header = array(
            'borders' => array(
            'bottom' => $default_border,
            'left' => $default_border,
            'top' => $default_border,
            'right' => $default_border,
            ),
    
            'fill' => array(
            'type' => PHPExcel_Style_Fill::FILL_SOLID,
            'color' => array('rgb'=>'E1E0F7')
            ),
            
            'font' => array(
            'bold' => true,
            )
    );
 
    $colorbereich = "A".$r.":B".$r;
    $objPHPExcel->getActiveSheet()->getStyle($colorbereich)->applyFromArray( $style_header );


    // Zeile 1 - Auftragsnummer
    $objPHPExcel->getActiveSheet()
                ->setCellValueByColumnAndRow($c, $r, "Auftragsnummer:")         // A1
                ->setCellValueByColumnAndRow($c+1, $r, $row['Auftragsnummer']);         // B1
                    
                    
    // Zeile 2 - Kunde
    $r++;
    $objPHPExcel->getActiveSheet();
    $objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow($c, $r, 'Kunde:')
                ->setCellValueByColumnAndRow($c+1, $r, readCustomer($row["Kundennummer"]));
        
    // Zeile 3 - Uhrzeit
    $r++;
    $objPHPExcel->getActiveSheet()
                ->setCellValueByColumnAndRow($c, $r, 'Einsatzzeit:')
                ->setCellValueByColumnAndRow($c+1, $r, date("H:i",strtotime($row["Von"]))." Uhr bis ".date("H:i", strtotime($row["Bis"]))." Uhr"."| Region: ".$row["Region"]);
        
    // Zeile 4 - Crew
    $r++;
    $objPHPExcel->getActiveSheet()
                ->setCellValueByColumnAndRow($c, $r, 'Crew:')
                ->setCellValueByColumnAndRow($c+1, $r, $row["Crew_1"]." ".$row["Crew_2"]." ".$row["Crew_3"]." ".$row["Crew_4"]." ".$row["Crew_5"]);
                    
    // Zeile 5 - Start- Landeplatz
    $r++;
    $objPHPExcel->getActiveSheet()
                ->setCellValueByColumnAndRow($c, $r, 'Start / Landung:')
                ->setCellValueByColumnAndRow($c+1, $r, $row["Startplatz"]." ".$row["Landeplatz"]);
                
    // Zeile 6 - Auf- Abladeplatz
    $r++;
    $objPHPExcel->getActiveSheet()          
                ->setCellValueByColumnAndRow($c, $r, 'Auf- / Abladeplatz:')         
                ->setCellValueByColumnAndRow($c+1, $r, $row["Aufladeplatz"]." ".$row["Abladeplatz"]);
    
    // Zeile 7 - Material
    $r++;
    $objPHPExcel->getActiveSheet()
                ->setCellValueByColumnAndRow($c, $r, 'Material:')
                ->setCellValueByColumnAndRow($c+1, $r, $row["Material"]);
                
    // Zeile 8 - Bemerkungen
    $r++;
    $objPHPExcel->getActiveSheet()
                ->setCellValueByColumnAndRow($c, $r, 'Bemerkungen:')
                ->setCellValueByColumnAndRow($c+1, $r, $row["Bemerkungen"]);            
    
    // Zeile 9 - Infos für Rückfragen
    $r++;
    $objPHPExcel->getActiveSheet()
                ->setCellValueByColumnAndRow($c, $r, 'Verrechnungsbasis:')
                ->setCellValueByColumnAndRow($c+1, $r, $row["Verrechnungsbasis"]);          
    
    // Zeile 10 - Leerzeile
    $r++;
    $objPHPExcel->getActiveSheet()
                ->setCellValueByColumnAndRow($c, $r, "")
                ->setCellValueByColumnAndRow($c+1, $r, ""); 
                

    // Seitenumbruch
    if ($counter % 4 == 0) {
        $breakpoint = "A".$r;
        $objPHPExcel->getActiveSheet()->setBreak( $breakpoint, PHPExcel_Worksheet::BREAK_ROW );
    }

    // Zähler der Zeilen um 1 erhöhen
    $r = $r+1;  
    
    // #################### Ende des Blocks ####################

}

// Druckbereich muss festgelegt werden
$druckbereich .= "A1:B".$r;
$objPHPExcel->getActiveSheet()->getPageSetup()->setPrintArea($druckbereich);

// Korrekten Namen vergeben
$objPHPExcel->getActiveSheet()->setTitle($Datum);

// Speichern im Format 2007
$callStartTime = microtime(true);

$objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel2007');
$objWriter->save("excel/".$Datum."-".$Immatrikulation.".xlsx");
$callEndTime = microtime(true);
$callTime = $callEndTime - $callStartTime;

// Browserausgabe
$objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel2007');
$objWriter->save('php://output'); 

?>
But the file "tagesplan_gesamt.php" is existing! What do I wrong? Thank you very much.

Torsten
Jun 17, 2013 at 9:10 AM
OK - I found one interesting thing: the file is created. I can see it with FTP in the folder.
Jun 17, 2013 at 9:52 AM
The "" tagesplan_gesamt.php"" file contains the code listed above?
Although I do not think that the problem is there (although I wonder where does the content of the $Immatrikulation variable that is used in the query and the file name).
The error message is probably generated by the Web server, not the script engine. If the file name is correct, the problem is the path: an error in the link or in the assessment of the path as sees the server...
Jun 17, 2013 at 10:07 AM
OK - Thank you very much. I will have a look. It seems, that the download of the file ist not starting. When I am home again I will see. I keep you informed.
Jun 17, 2013 at 12:43 PM
The path seen by the FTP server is not necessarily the same as seen by the Web server.
You can try to replace your file by another with the same name but very simple content and check that the Navigator happens to get it by following the link.
Link to search carefully: a '.' or ' /' forgotten or too change the deal, not to mention the configuration of the servers Web (DocumentRoot, aliases...)