0
I have the following code:
mudarfoto.php
<div class="box-body">
<center><h4 style="padding:5%">Vamos trocar a imagem da seção projetos?</h4></center>
<?php
$hostdb = "***";
$userdb = "***";
$passdb = "***";
$tabledb = "***";
$conecta = mysql_connect($hostdb, $userdb, $passdb) or die (mysql_error());
@mysql_select_db($tabledb, $conecta) or die ("Erro ao conectar com o banco de dados");
mysql_set_charset('UTF8');
$busca_query = mysql_query("SELECT * FROM projetos WHERE id = $id") or die (mysql_error());
$row = mysql_fetch_array($busca_query); ?>
<form class="form-horizontal" id="alterarproduto" autocomplete="on" method="post" action="chgfotosprojetos-alterar-confirmar.php">
<fieldset>
<br><br>
<iframe width="600" name="frmfoto" height="300" frameborder="0" src="fotos.php"></iframe>
<script type="text/javascript">
function txfoto() {
//Pega o iframe
var frmfoto = $("iframe[name=frmfoto]");
//Pega o input dentro do iframe
var input = $("#foto", frmfoto.get(0).contentWindow.document);
//Passa o valor do input do iframe para o input na janela principal
$('#fotofundo').val( input.val() );
}
</script>
<!-- FOTO 1 -->
<div class="form-group">
<label class="col-md-2 control-label" for="fotofundo">* Foto 01</label>
<div class="col-md-5">
<input id="fotofundo" name="fotofundo" type="text" placeholder="" class="form-control input-md" onClick="txfoto()" />
</div>
</div>
<br><br>
<!-- LEGENDA DA FOTO -->
<div class="form-group">
<label class="col-md-2 control-label" for="legendafoto">* Legenda da Foto</label>
<div class="col-md-5">
<input id="legendafoto" name="legendafoto" type="text" placeholder="" class="form-control input-md" value="<?php echo $row['legendafoto'] ?>">
</div>
</div>
<br><br>
<input type="hidden" value="<?php echo $id; ?>" name="id" />
<!-- Button "MODIFICAR DADOS" -->
<center><input type="submit" class="btn btn-primary" value="Modificar Dados" /></center>
</div>
php photos.
<div class="container">
<form action="<?php echo $_SERVER['PHP_SELF'];?>" method="post" enctype="multipart/form-data">
<input type="file" name="image" />
<input type="submit" name="submit" value="Submit" />
</form>
</div>
if(isset($_POST["submit"])) {
if(is_array($_FILES)) {
$file = $_FILES['image']['tmp_name'];
$sourceProperties = getimagesize($file);
$fileNewName = time();
$folderPath = "upload/";
$ext = pathinfo($_FILES['image']['name'], PATHINFO_EXTENSION);
$imageType = $sourceProperties[2];
switch ($imageType) {
case IMAGETYPE_PNG:
$imageResourceId = imagecreatefrompng($file);
$targetLayer = imageResize($imageResourceId,$sourceProperties[0],$sourceProperties[1]);
imagepng($targetLayer,$folderPath. $fileNewName. "_thump.". $ext);
break;
case IMAGETYPE_GIF:
$imageResourceId = imagecreatefromgif($file);
$targetLayer = imageResize($imageResourceId,$sourceProperties[0],$sourceProperties[1]);
imagegif($targetLayer,$folderPath. $fileNewName. "_thump.". $ext);
break;
case IMAGETYPE_JPEG:
$imageResourceId = imagecreatefromjpeg($file);
$targetLayer = imageResize($imageResourceId,$sourceProperties[0],$sourceProperties[1]);
imagejpeg($targetLayer,$folderPath. $fileNewName. "_thump.". $ext);
break;
default:
echo "Invalid Image type.";
exit;
break;
}
move_uploaded_file($file, $folderPath. $fileNewName. ".". $ext);
}
}
function imageResize($imageResourceId,$width,$height) {
$targetWidth =800;
$targetHeight =600;
$targetLayer=imagecreatetruecolor($targetWidth,$targetHeight);
imagecopyresampled($targetLayer,$imageResourceId,0,0,0,0,$targetWidth,$targetHeight, $width,$height);
return $targetLayer;
}
$finalfile = $fileNewName. "_thump.". jpg;
// echo "$folderPath$finalfile"
?>
<img src="<?php echo "$folderPath$finalfile"; ?>" alt="Sua foto" class="img-responsive" width="200px" />
<input id="foto" name="foto" type="hidden" class="form-control input-md" value="<?php echo "$folderPath$finalfile"; ?>">
The event onClick
works perfectly. But, if possible, I would like to have the input
automatically updated without the need for the click. It is possible?
Automatic how? There has to be an event, be it a user, server action or a timer that updates from time to time
– Ricardo Pontual
I understand. I asked the question, by the possibility of using a "load" event in iframe, I do not know and I do not know if it works. I am very weak in javascript...
– Hebert Richard Masseno Dias
Yes it is possible, you can use the * load* event from
iframe
to change an input on the page Parent– Ricardo Pontual
Thank you. Some example or form of research, for me to apply in my code? As I said before, I am weak in javascript.
– Hebert Richard Masseno Dias
You’ll get better answers if you give people code they can use to reproduce the problem
– user60252
Complete code entered, @Leocaracciolo
– Hebert Richard Masseno Dias
Please read https://pt.meta.stackoverflow.com/questions/1078/como-e-por-que-aceitar-uma-resposta/1079#1079
– user60252
I will, thanks for the support, @Leocaracciolo
– Hebert Richard Masseno Dias