Ir para conteúdo

POWERED BY:

Arquivado

Este tópico foi arquivado e está fechado para novas respostas.

visitante_php

[Resolvido] a data muda

Recommended Posts

criei um script pra upload que redimensiona e troca o nome da foto pela data e hora....so q na hora q gravar a imagem no servidor grava com um segundo, e na hora dew gravar no banco muda um segundo, como resolvo...?

Compartilhar este post


Link para o post
Compartilhar em outros sites

Você deve definir o nome em uma variável, e utilizá-la sempre, sem redefinir o nome posteriormente.

Compartilhar este post


Link para o post
Compartilhar em outros sites

eu usei uma data para nao ter q renomea-la manualmente, pra toda vez q upar uma foto...mudar o nome sem sobrescrever uma anterior....como faço isso? pensei em time...mas vai mudar....keria uma dica...

Compartilhar este post


Link para o post
Compartilhar em outros sites

Deixe eu ver esta parte do código, onde você cria o nome do arquivo e o renomeia.

Compartilhar este post


Link para o post
Compartilhar em outros sites

<?php
include("control/dados.class.php");
include("control/class.html.php");
$banco = new dados("odebateon");
$codigo = new Html();
if($_POST){
if(isset($_FILES["foto"])){
	
	

//nome do arquivo no campo de envio

$arquivo = $_FILES["foto"];

//nesse caso um nome para relaciona-lo no db
// colocar o nome original eh chato

$nome = $_POST['titulo'];

//lugar onde ficara as extensoes permitidas
//usar o mimetype para verificar a extensao
$ext = array("jpeg", "jpg", "txt", "pdf", "gif");

//nome temporario do arquivo

$name = $arquivo['name'];
$parte1 = explode(".",$name);
$parte2 = date("d_m_Y_H_i_s");
$nomes = array($parte2, $parte1["1"]);
$parte3 = implode(".",$nomes);
//$arquivo['tmp_name'] = $name;

$pasta_dir = "testes/";//diretorio dos arquivos

//se nao existir a pasta ele cria uma

/*

if(!file_exists($pasta_dir)){

mkdir($pasta_dir);

}

*/

//cria um novo nome para o arquivo com
// o com a path do arquivo

$arquivo_nome = $pasta_dir . $parte3;

// Faz o upload da imagem

//tamanho maximo permitido, sempre em bytes,
// nesse caso o arquivo so pode ter 100kb(1024b*100)

if($arquivo['size']>102400){

// se arquivo maior de 100 kb

echo "Somente arquivos com 100 kb!<br>";

}elseif($arquivo['type'] != in_array(substr($parte3, -3),$ext)){

//se a extensao nao estiver permitida no array la emcima

echo "Extensao de arquivo nao permitida!<br>";

}else{

//The file
$filename2 = $arquivo['tmp_name'];
$filename3 = $arquivo['tmp_name'];
// Set a maximum height and width
$width2 = 100;
$height2 = 75;
$width3 = 361;
$height3 = 256;
// Content type
//header('Content-type: image/jpeg');

// Get new dimensions
// Get new dimensions
list($width_orig, $height_orig) = getimagesize($filename2);

if ($width2 && ($width_orig < $height_orig)) {
	$width2 = ($height2 / $height_orig) * $width_orig;
} else {
	$height2 = ($width2 / $width_orig) * $height_orig;
}

list($width_orig2, $height_orig2) = getimagesize($filename3);

if ($width3 && ($width_orig2 < $height_orig2)) {
	$width3 = ($height3 / $height_orig2) * $width_orig2;
} else {
	$height3 = ($width3 / $width_orig2) * $height_orig2;
}
// Resample
$image_p = imagecreatetruecolor($width2, $height2);
$image = imagecreatefromjpeg($filename2);
imagecopyresampled($image_p, $image, 0, 0, 0, 0, $width2, $height2, $width_orig, $height_orig);
imagejpeg($image_p, $pasta_dir."thumb_".$parte3, 100);
$image_p2 = imagecreatetruecolor($width3, $height3);
$image2 = imagecreatefromjpeg($filename3);
imagecopyresampled($image_p2, $image2, 0, 0, 0, 0, $width3, $height3, $width_orig2, $height_orig2);
imagejpeg($image_p2, $pasta_dir.$parte3, 90);
//move_uploaded_file($arquivo['tmp_name'], $pasta_dir.date("YmdHis").".jpg");
$banco->Query("INSERT INTO noticias (fk_cat, fk_subcat,titulo, subtitulo,autor, creditos,data, texto,palavra_chave,foto_destaque,foto_interna,legenda, destaque,leitor,secao) VALUES('".$_POST['fk_cat']."','".$_POST['fk_subcat']."','".$_POST['titulo']."','".$_POST['subtitulo']."','".$_POST['autor']."','".$_POST['creditos']."','".$_POST['data']."','".$_POST['texto']."','".$_POST['palavra_chave']."','".$pasta_dir."thumb_".$parte3."','".$pasta_dir.date("d_m_Y_H_i_s").".jpg"."','".$_POST['legenda']."','".$_POST['destaque']."','".$_POST['leitor']."','".$_POST['secao']."')");
}
}
}
?>
<!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>Untitled Document</title>
<script type="text/javascript" src="js/date-picker/js/datepicker.js"></script>
<link href="tema.css" rel="stylesheet" type="text/css" />
<link href="js/date-picker/css/datepicker.css" rel="stylesheet" type="text/css" />
<script type="text/javascript">
//<![CDATA[

/* The following function creates a new input field and then calls datePickerController.create();
   to dynamically create a new datePicker widgit for it */
function newline() {
		var total = document.getElementById("newline-wrapper").getElementsByTagName("table").length;
		total++;

		// Clone the first div in the series
		var tbl = document.getElementById("newline-wrapper").getElementsByTagName("table")[0].cloneNode(true);

		// DOM inject the wrapper div
		document.getElementById("newline-wrapper").appendChild(tbl);

		var buts = tbl.getElementsByTagName("a");
		if(buts.length) {
				buts[0].parentNode.removeChild(buts[0]);
				buts = null;
		}

		// Reset the cloned label's "for" attributes
		var labels = tbl.getElementsByTagName('label');

		for(var i = 0, lbl; lbl = labels[i]; i++) {
				// Set the new labels "for" attribute
				if(lbl["htmlFor"]) {
						lbl["htmlFor"] = lbl["htmlFor"].replace(/[0-9]+/g, total);
				} else if(lbl.getAttribute("for")) {
						lbl.setAttribute("for", lbl.getAttribute("for").replace(/[0-9]+/, total));
				}
		}

		// Reset the input's name and id attributes
		var inputs = tbl.getElementsByTagName('input');
		for(var i = 0, inp; inp = inputs[i]; i++) {
				// Set the new input's id and name attribute
				inp.id = inp.name = inp.id.replace(/[0-9]+/g, total);
				if(inp.type == "text") inp.value = "";
		}

		// Call the create method to create and associate a new date-picker widgit with the new input
		datePickerController.create(document.getElementById("date-" + total));

		var dp = datePickerController.datePickers["dp-normal-1"];

		// No more than 5 inputs
		if(total == 5) document.getElementById("newline").style.display = "none";

		// Stop the event
		return false;
}

function createNewLineButton() {
		var nlw = document.getElementById("newline-wrapper");

		var a = document.createElement("a");
		a.href="#";
		a.id = "newline";
		a.title = "Create New Input";
		a.onclick = newline;
		nlw.parentNode.appendChild(a);

		a.appendChild(document.createTextNode("+"));
		a = null;
}

datePickerController.addEvent(window, 'load', createNewLineButton);

//]]>
</script>

</head>

<body>
<?php
//cria os campos
$fk_cat		= $codigo->AddTextField("fk_cat","hidden",1);
$fk_subcat	 = $codigo->AddTextField("fk_subcat","hidden",1);
$secao		 = $codigo->AddTextField("secao","hidden",1);
$titulo		= $codigo->AddTextField("titulo");
$subtitulo	 = $codigo->AddTextField("subtitulo");
$autor		 = $codigo->AddTextField("autor");
$creditos	  = $codigo->AddTextField("creditos");
$data		  = $codigo->AddTextField("data","text","","w6em format-d-m-y highlight-days-67");//
$texto		 = $codigo->AddTextArea("texto");
$legenda	   = $codigo->AddTextField("legenda");
$leitor		= $codigo->AddTextField("leitor","hidden",0);
$foto		  = $codigo->AddTextField("foto","file");
$destaque	   = $codigo->AddCheckBox("destaque",1);

$titulo_label		= $codigo->AddLabel("Titulo",$titulo);
$subtitulo_label	 = $codigo->AddLabel("Subtitulo", $subtitulo);
$autor_label		 = $codigo->AddLabel("Autor",$autor);
$creditos_label	  = $codigo->AddLabel("Creditos", $creditos);
$data_label		  = $codigo->AddLabel("Data",$data);
$texto_label		 = $codigo->AddLabel("Texto", $texto);
$foto_label		  = $codigo->AddLabel("Foto", $foto);
$legenda_label	   = $codigo->AddLabel("Legenda", $legenda);
$destaque_label	  = $codigo->AddLabel("Destaque", $destaque);

$codigo->SetAction($_SERVER['PHP_SELF']);
$codigo->SetButton("envia", "Enviar");
$codigo->SetEnctype(0);
$codigo->SetMethod();

echo $codigo->CreateForm("cadastro_noticias",array($titulo_label,$subtitulo_label,$autor_label,$creditos_label, $data_label, $texto_label, $foto_label, $legenda_label, $destaque_label));
?>
</body>
</html>

o arquivo eh esse, to usando uma classe q criei para o mysql e uma outra para gerar forms em html....

Compartilhar este post


Link para o post
Compartilhar em outros sites

Bom, esta linha está comentada, se refere-se a esta, é porque você está recriando o nome do arquivo, ao invés de utilizar o nome previamente criado:

 

//move_uploaded_file($arquivo['tmp_name'], $pasta_dir.date("YmdHis").".jpg");

Compartilhar este post


Link para o post
Compartilhar em outros sites

o problema nessa linha eh q nao kero a foto no tamanho original, e sim de 2 tamanhos...

 

a linha q da problema eh essa

 

$name = $arquivo['name'];

$parte1 = explode(".",$name);

$parte2 = date("d_m_Y_H_i_s");

$nomes = array($parte2, $parte1["1"]);

$parte3 = implode(".",$nomes);

//$arquivo['tmp_name'] = $name;

 

eu at coloquei uma md5 do nome original...mas da diferente...

Compartilhar este post


Link para o post
Compartilhar em outros sites

×

Informação importante

Ao usar o fórum, você concorda com nossos Termos e condições.