Upload de Arquivos maiores que 20Mb
Olá galera no imasters, depois de mtas horas procurando, finalmente encontrei um upload de arquivos zip q funcione e q descompacta os arquivos em uma pasta, pois bem, o codigo abaixo faz o upload legal e descompacta, o problema eh q se eu tentar subir um arquivo zip cm 150 fotos compactadas, q eh a media por galeria, o arquivo zip fica cm uns 12Mb, sendo q pode ter eventos q precise de mais, entao botei logo 20Mb no titulo, certo, mas como 12Mb demora um pouco pra carregar, entao axo q espira a pagina ou sei lah, sei q ele vai carregando e carregando, depois de um tmp ela tipo cansa e para, fiz uns testes e consegui subir ate 8mb, pensei em por tipo aqueles loading, q vai dizendo o tanto q jah transferiu, mas nao axei ainda um q funcione, alguma ideia pra me ajudar? brgd!
<?php
set_time_limit(0);
function openZip($file_to_open) {
global $target;
global $unique_folder;
$zip = new ZipArchive();
$x = $zip->open($file_to_open);
if ($x === true) {
$zip->extractTo($target . $unique_folder);
$zip->close();
unlink($file_to_open);
}
else { die("Ocorreu um problema. Favor tente novamente!"); }
}
if(isset($_FILES['fupload'])) {
$filename = $_FILES['fupload']['name'];
$source = $_FILES['fupload']['tmp_name'];
$type = $_FILES['fupload']['type'];
$name = explode('.', $filename); # $name[0] returns the name of the file. $name[1] returns the extension (zip)
$target = 'imgs/coberturas/' . $name[0] . '/'; # Where the file will be saved. I.E. 'extracted/myFile-02151985/'
// Ensures that the correct file type was chosen.
$accepted_types = array('application/zip', 'application/x-zip-compressed', 'multipart/x-zip', 'application/x-compressed');
foreach($accepted_types as $mime_type) {
if($mime_type == $type) {
$okay = true;
break;
}
}
// Safari/Chrome don't register zip mime types. Something better could be used here - with the use of the PEAR extension.
$okay = strtolower($name[1]) == 'zip' ? true : false;
if(!$okay) { die("Favor, selecione um arquivo zip!"); }
#$unique_folder = $name[0] . '-' . time() . '/';
mkdir($target);
$saved_file_location = $target . $filename;
if(move_uploaded_file($source, $target . $filename)) {
openZip($saved_file_location);
}else { die("Ocorreu um erro");}
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Inserir Cobertura</title>
</head>
<body>
<form enctype="multipart/form-data" action="" method="post">
<table width="500" border="0" cellpadding="0" cellspacing="2">
<tr>
<td width="100">Titulo:</td>
<td width="394"><input name="titulo" type="text" id="titulo" size="60" /></td>
</tr>
<tr>
<td>Data:</td>
<td> </td>
</tr>
<tr>
<td>Cobertura:</td>
<td><input type="file" name="fupload" /></td>
</tr>
<tr>
<td></td>
<td><input type="submit" value="Enviar Cobertura" /></td>
</tr>
</table>
</form>
</body>
</html>
andei lendo e vi q tinha tipo um tmp pra expirar, e axei esse cod, mas mesmo assim nao ajudou.
<?php
set_time_limit(0);
?>Discussão (9)
Carregando comentários...