Error when uploading .docx with Php?

0

Hello to all of you I charge different types of files and I keep them in a folder and I store the path in the BD, all the files load them well (.doc, xls ...) except (docx, xlsx ...) .Docx files it is copied to the directory but it is not possible to obtain its name, size type etc.

This is my code:

<?php
require_once 'connect.php';
if($_POST) {
    $nombre = $_FILES['archivo']['name'];
    $tipo = $_FILES['archivo']['type'];
    $tamanio = $_FILES['archivo']['size'];
    $ruta = $_FILES['archivo']['tmp_name'];
    $destino = "../archivos/" . $nombre;    

    copy($ruta, $destino);
    $sql = "INSERT INTO documentos (tipo,tamano,destino,fecha) VALUES ('$tipo', '$tamanio', '$nombre',NOW())";
    $query = $connect->query($sql);

    $connect->close();

}
    
asked by Rastalovely 25.03.2017 в 16:52
source

2 answers

0

you could create an arrangement with the valid formats to upload.

$formatos = array("jpg", "png", "gif", "bmp", "zip", "rar", "doc", "docx", "xls", "xlsx", "pdf");

later you could validate the file extension.

if(isset($_POST) and $_SERVER['REQUEST_METHOD'] == "POST"){
 foreach ($_FILES['files']['name'] as $f => $name) {     
  if ($_FILES['files']['error'][$f] == 4) {
            continue;
      } 
  elseif( ! in_array(pathinfo($name, PATHINFO_EXTENSION), $formatos) ){
                    $message[] = "$name formtato no valido";
                    continue; 
                }
      }
}

or less serious in this way.

    
answered by 25.03.2017 в 17:58
0

The problem is in mimes.php

In the line corresponding to doc and docx, change to the following:

'doc'   =>  array('application/msword', 'application/vnd.ms-office','application/vnd.oasis.opendocument.text'),
'docx'  =>  array('application/vnd.openxmlformats-officedocument.wordprocessingml.document', 'application/zip', 'application/msword', 'application/x-zip','application/vnd.oasis.opendocument.text','application/octet-stream'),

Also, make sure that you accept files with extension doc and docx. For example:

$config['allowed_types'] = 'application/vnd.oasis.opendocument.spreadsheet | application/vnd.oasis.opendocument.text | application/vnd.oasis.opendocument.presentation | 

application / vnd.openxmlformats-officedocument.wordprocessingml.document | application / vnd.ms-excel | application / vnd.openxmlformats-officedocument.presentationml.presentation | txt | gif | jpg | png | pdf | ods | odt | xls | xlsx | docx | doc ';

    
answered by 27.01.2018 в 22:46