Jump to content
Fórum Script Brasil
  • 0

Problema com script zipFile


claytonprog

Question

Pessoal!

estou com um problema num envio de fotos com zipFile. Ele faz o envio corretamente porém ele renomeias as fotos e isso eu não quero!! Alguém saberia mudar esse script para ele não renomear as fotos!

Segue abaixo o script.

<?php

//VERIFICA SE A SESSÃO ESTÁ ATIVA 
require_once("verifica.php"); 

//CONECTA COM O BANCO DE DADOS 
require_once("../connections/conexao.php");      
    
include("helpers.php");
    
    //mysql_connect ($sql_host, $sql_user, $sql_pass);
   // mysql_select_db ($sql_db);
    if (isset($_FILES['zipfile']['name'])) {
        $albumId = $_POST['album_id'];
        
        //$albumPath = mysql_result(mysql_query("SELECT FROM album_projeto WHERE id='" . $albumId . "'"),0);
        
        $zipFile = $_FILES['zipfile']['tmp_name'];
        $albumDir = 'fotos_album/';        
        //$albumDir = $root_dir . "images/" . $albumPath;
        $uploadDir = $albumDir . "tmp";
        
        if (!file_exists($uploadDir)) mkdir($uploadDir);
        if (@is_uploaded_file($zipFile))
        {
            $extension = getFileExtension($_FILES['zipfile']['name']);
            $now = time();
            
            while(file_exists($newFile = $uploadDir.'/'.$now.'.'.$extension)) {
                $now++;
            }
            
            $uploadedFileName = $now.'.'.$extension;
            move_uploaded_file($_FILES['zipfile']['tmp_name'], $newFile);
            $zip = new ZipArchive;
            $handle = $zip->open($newFile);
            if ($handle === TRUE) {
                echo "<b>Fotos Enviadas com sucesso!</b>";
                  echo "<script language='javaScript'>window.location.href='fotos.php'</script>";
                
                $zip->extractTo($uploadDir);
                $zip->close();
            } else {
                echo 'Falha, código:' . $handle;
            }
            unlink($newFile);
            if ($handle = opendir($uploadDir)) {
                while (false !== ($file = readdir($handle))) {
                    if ($file == "." || $file == "..") continue;
                    $extension = getFileExtension($file);
                    $now = time();
                    
                    while(file_exists($newFile = $albumDir.'/'.$now.'.'.$extension)) {
                        $now++;
                    }
                    
                    $fileName = $now . '.' . $extension;
                    rename($uploadDir.'/'.$file,$newFile);                                                        
                            
                    $arquivo = $fileName;
                    $path_foto = $arquivo;
            
                    $query = "INSERT INTO fotos (id_foto, id_album ,foto) VALUES('','$albumId','$path_foto')";
                                    
                                    
                    $result = mysql_query($query);
                }
            }
        }
        
    }


?>

Link to comment
Share on other sites

1 answer to this question

Recommended Posts

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Answer this question...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.



  • Forum Statistics

    • Total Topics
      152.2k
    • Total Posts
      652k
×
×
  • Create New...