Jump to content

Recommended Posts

Posted

Boas pessoal,

A minha dúvida é a seguinte:

Estou a "melhorar" uma area de cliente de um cliente do qual fiquei com o site novo para fazer, mas que ele quer algumas alterações nessa area do cliente, além do design.

Na area do cliente, aparecem as fotos todas dispostas por tabelas. Mas estas imagens são carregadas através do FTP, e não para a BD (o cliente usa um programa ftp e manda para lá as fotos) Daí está a minha duvida: O cliente quer que apareça o titulo da imagem (por ex: 001.jpg) e com a checkbox. Depois de clicar em seguinte, vai para umas ficha de preenchimento, onde na parte onde tenha "fotos para encomenda" sejam as seleccionadas atrás.

Não sei se me fiz entender.

O código que tenho é este, já um pouco alterado por mim:

// Mysql_num_row is counting table row

$count = mysql_num_rows($result);

// If result matched $myusername and $mypassword, table row must be 1 row

if($count==1 && $username!="")

{

$imgdir = $username . '/'; // the directory, where your images are stored

$allowed_types = array('png','jpg','jpeg','gif'); // list of filetypes you want to show

$dimg = opendir($imgdir);

while($imgfile = readdir($dimg))

{

if(in_array(strtolower(substr($imgfile,-3)),$allowed_types))

{

$a_img[] = $imgfile;

sort($a_img);

reset ($a_img);

}

}

$totimg = count($a_img); // total image number

echo "<table width=\"900\" cellspacing=\"0\" align=\"center\" cellpadding=\"0\"><tr><td class=\"table_header\">Nome de utilizador: " . $username . "<br>N� de fotos: " . $totimg . "</td></tr></table><table width=\"900\" align=\"center\" cellspacing=\"5\" cellpadding=\"0\" bordercolor=\"#000000\">";

for($x=0; $x < $totimg; $x+=5)

{

//if($x==0){$inc="lightbox[1]";}else{$inc="group";}

echo "<tr>

<td align=\"center\" width=\"100\" class=\"table_row\">

<a href=\"" . $imgdir . $a_img[$x] . "\" rel=\"pp[1]\">

<img src=\"" . $imgdir . $a_img[$x] . "\" width=\"120\" border=\"0\"/> ['titulo'];</a>

</td>

<td width=\"100\" align=\"center\" class=\"table_row\">

<a href=\"" . $imgdir . $a_img[$x+1] . "\" rel=\"pp[1]\">

<img src=\"" . $imgdir . $a_img[$x+1] . "\" width=\"120\" border=\"0\"/></a>

</td>

<td width=\"100\" align=\"center\" class=\"table_row\">

<a href=\"" . $imgdir . $a_img[$x+2] . "\" rel=\"pp[1]\">

<img src=\"" . $imgdir . $a_img[$x+2] . "\" width=\"120\" border=\"0\"/></a>

</td>

<td width=\"100\" align=\"center\" class=\"table_row\">

<a href=\"" . $imgdir . $a_img[$x+3] . "\" rel=\"pp[1]\">

<img src=\"" . $imgdir . $a_img[$x+3] . "\" width=\"120\" border=\"0\"/></a>

</td>

<td width=\"100\" align=\"center\" class=\"table_row\">

<a href=\"" . $imgdir . $a_img[$x+4] . "\" rel=\"pp[1]\">

<img src=\"" . $imgdir . $a_img[$x+4] . "\" width=\"120\" border=\"0\"/></a>

</td>

<td width=\"100\" align=\"center\" class=\"table_row\">

<a href=\"" . $imgdir . $a_img[$x+5] . "\" rel=\"pp[1]\">

<img src=\"" . $imgdir . $a_img[$x+5] . "\" width=\"120\" border=\"0\"/></a>

</td>

</tr>";

}

Este código e da página onde aparecem as fotos. Depois só precisava do código que tenho de por na textfield para aparecerem as fotos selecionadas.

Se me puderem ajudar, fico mesmo agradecido 😉

Obrigado

Posted

Se eu meter isso assim:

echo "<tr>

<td align=\"center\" width=\"100\" class=\"table_row\">

<a href=\"" . $imgdir . $a_img[$x] . <input type="checkbox" name="images" value="1" />."\" rel=\"pp[1]\">

<img src=\"" . $imgdir . $a_img[$x] . "\" width=\"120\" border=\"0\"/> </a>

</td>

A página nem carrega. Fica em branco :S

Posted

Em vez de

echo "bla bla
ble ble
...
blu blu";

experimenta

?>
bla bla
ble ble
...
blu blu
<?php

Se tiveres uma coisita ou outra dentro do bla bla que precise de php, volta a entrar e sair do modo php ...

?>
bla bla
ble <?php echo $_SESSION['username']; ?> ble
...
blu blu
<?php

What have you tried?

Não respondo a dúvidas por PM

A minha bola de cristal está para compor; deve ficar pronta para a semana.

Torna os teus tópicos mais atractivos e legíveis usando a tag CODE para colorir o código!

Posted

Num ficheiro php, tudo o que nao esta dentro das tags php é html

<?php
// aqui é php
?>
<!-- Aqui é HTML -->
<?php
# aqui é php outra vez
echo 'aqui é HTML';

$nome = 'John Doe';
$idade = 42;
echo <<<END
Aqui também é HTML com parsing automatico :-)
Exemplo: O $nome tem $idade anos.
END
?>

What have you tried?

Não respondo a dúvidas por PM

A minha bola de cristal está para compor; deve ficar pronta para a semana.

Torna os teus tópicos mais atractivos e legíveis usando a tag CODE para colorir o código!

Posted

Então o que propões é, em vez de:

      echo "<tr>
      <td align=\"center\" width=\"100\" class=\"table_row\">
         <a href=\"" . $imgdir . $a_img[$x] ."\" rel=\"pp[1]\">
            <img src=\"" . $imgdir . $a_img[$x] . "\" width=\"120\" border=\"0\"/> </a>
<input type="checkbox" name="images" value="1" />
      </td>

colocar:

     <? <tr>
      <td align=\"center\" width=\"100\" class=\"table_row\">
         <a href=\"" . $imgdir . $a_img[$x] ."\" rel=\"pp[1]\">
            <img src=\"" . $imgdir . $a_img[$x] . "\" width=\"120\" border=\"0\"/> </a>

<?php <input type="checkbox" name="images" value="1" />?>

      </td> ?>
Posted
      echo <<<HTML001
      <tr>
      <td align="center" width="100" class="table_row">
         <a href="$imgdir{$a_img[$x]}" rel="pp[1]">
            <img src="$imgdir{$a_img[$x]}" width="120" border="0"/> </a>
<input type="checkbox" name="images" value="1" />
      </td>
HTML001;

What have you tried?

Não respondo a dúvidas por PM

A minha bola de cristal está para compor; deve ficar pronta para a semana.

Torna os teus tópicos mais atractivos e legíveis usando a tag CODE para colorir o código!

Posted

Mudei consoante o que me disseste, mas não deu nada. Apareceu a página toda em branco  ?

Deixo aqui o código toda da página:

<!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>
	<script src="js/jquery-1.6.1.min.js" type="text/javascript"></script>
	<!--script src="js/jquery.lint.js" type="text/javascript" charset="utf-8"></script-->
	<link rel="stylesheet" href="css/prettyPhoto.css" type="text/css" media="screen" title="prettyPhoto main stylesheet" charset="utf-8" />
	<script src="js/jquery.prettyPhoto.js" type="text/javascript" charset="utf-8"></script>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Fernando Tavares</title>
<link rel="stylesheet" type="text/css" href="css.css" />
    <script src="AC_RunActiveContent.js" type="text/javascript"></script>
    
            <script type="text/javascript" src="script.js"></script>

</head>

<body>
<?php
include("header.php");
?>

<?php
include("database_connect.php");
?>

<?php
$username = $_POST['username'];
$password = $_POST['pass'];
$sql = "SELECT * FROM clientes WHERE utilizador='$username' AND palavra='$password'";
$result = mysql_query($sql);

// Mysql_num_row is counting table row
$count = mysql_num_rows($result);
// If result matched $myusername and $mypassword, table row must be 1 row

if($count==1 && $username!="")
{
$imgdir = $username . '/'; // the directory, where your images are stored
$allowed_types = array('png','jpg','jpeg','gif'); // list of filetypes you want to show
$dimg = opendir($imgdir);
while($imgfile = readdir($dimg))
{
	if(in_array(strtolower(substr($imgfile,-3)),$allowed_types))
	{
		$a_img[] = $imgfile;
		sort($a_img);
		reset ($a_img);
	} 
}
$totimg = count($a_img); // total image number

echo "<table width=\"900\" cellspacing=\"0\" align=\"center\" cellpadding=\"0\"><tr><td class=\"table_header\">Nome de utilizador: " . $username . "<br>N� de fotos: " . $totimg . "</td></tr></table><table width=\"900\" align=\"center\" cellspacing=\"5\" cellpadding=\"0\" bordercolor=\"#000000\">";
for($x=0; $x < $totimg; $x+=5)
{
	//if($x==0){$inc="lightbox[1]";}else{$inc="group";}

	echo <<<HTML001
      <tr>
      <td align="center" width="100" class="table_row">
         <a href="$imgdir{$a_img[$x]}">
            <img src="$imgdir{$a_img[$x]}" width="120" border="0"/> </a>
<input type="checkbox" name="images" value="1" />
      </td>


      <td align="center" width="100" class="table_row">
         <a href="$imgdir{$a_img[$x+1]}">
            <img src="$imgdir{$a_img[$x+1]}" width="120" border="0"/> </a>
<input type="checkbox" name="images" value="2" />
      </td>

      <td align="center" width="100" class="table_row">
         <a href="$imgdir{$a_img[$x+2]}">
            <img src="$imgdir{$a_img[$x+2]}" width="120" border="0"/> </a>
<input type="checkbox" name="images" value="3" />
      </td>

      <td align="center" width="100" class="table_row">
         <a href="$imgdir{$a_img[$x+3]}">
            <img src="$imgdir{$a_img[$x+3]}" width="120" border="0"/> </a>
<input type="checkbox" name="images" value="4" />
      </td>

      <td align="center" width="100" class="table_row">
         <a href="$imgdir{$a_img[$x+4]}">
            <img src="$imgdir{$a_img[$x+1]}" width="120" border="0"/> </a>
<input type="checkbox" name="images" value="5" />
      </td>

      <td align="center" width="100" class="table_row">
         <a href="$imgdir{$a_img[$x+5]}">
            <img src="$imgdir{$a_img[$x+5]}" width="120" border="0"/> </a>
<input type="checkbox" name="images" value="6" />
      </td>
  
	</tr>

HTML001;

}

echo "</table></table>";

} else {
print "Username ou Password Errados!";
}

?>

<?php
include("footer.php");
?>

Isto funciona assim:

Isto cria uma tabela com 6 colunas, que contém as fotos que o cliente manda para dentro do ftp. E vai criando rows, consoante a quantidade das fotos, sempre com 6 colunas.

A checkbox como está feita mete o nome da imagem?

Posted

Os <<< e o HTML001 sao parte da sintaxe "heredoc" ( http://pt2.php.net/manual/pt_BR/language.types.string.php#language.types.string.syntax.heredoc )

Atencao que o identificador final tem de estar colado a esquerda.

Em vez de HTML001 podes usar o que quiseres. Eu gosto de HTML001 para o primeiro pedaco de HTML embutido, HTML002 para o segundo, ... Tambem uso SQL001, SQL002 para embutir coisas da base de dados

What have you tried?

Não respondo a dúvidas por PM

A minha bola de cristal está para compor; deve ficar pronta para a semana.

Torna os teus tópicos mais atractivos e legíveis usando a tag CODE para colorir o código!

Posted

Consegui criar a check box.

      echo "<tr>
      <td align=\"center\" width=\"100\" class=\"table_row\">
         <a href=\"" . $imgdir . $a_img[$x] ."\">
            <img src=\"" . $imgdir . $a_img[$x] . "\" width=\"120\" border=\"0\"/> </a>
<input type='checkbox' name='images' value='1' />

      </td>

O problema agora é: Aparecer o nome do ficheiro. Um ex-stor meu disse-me assim:

se reparares tu estás a guardar num array o caminho da imagem

certo?

nesse caminho, está o nome da imagem

estilo v2/areadeclientes/abr1627/008.jpg

o q tens é de fazer uma substring dessa começando nos caracteres do fim até encontrar a /

e aí tens o nome da imagem

Só que ele já não se lembra qual o código para isso. Se alguém me conseguir dizer como se faz isso, agradecia.

Depois há outro situação, que é: Quando as pessoas selecionarem a foto, e no fim da página fizerem "seguinte" vai para uma página de preechimento de dados. No qual aparerá numa textfield o nome das fotos selecionadas. Alguém tem ideia qual o código a usar nessa textfield?

O meu ex-stor quando a isso disse:

Tens de criar um novo ciclo como o q tens e apresentar na text box o nome das imagens q na checkbox tiver o valor 1

Se alguém me ajudar a construir nos códigos, seria o ideal. Visto que não tenho ideia de como posso fazer isso. Obrigado 😉

Posted

Para apresentar apenas o nome do ficheiro :


// end() , muda o ponteiro do array para o último index
// explode() , divide uma string num array / conjunto de strings com base numa string passada

$img = end(explode('/', $a_img[$x]));

Para editar os dados do ficheiro, depende de que dados quiseres editar e a origem deles.

Posted

Obrigado yoda!

pus assim:

      echo "<tr>
      <td align=\"center\" width=\"100\" class=\"table_row\">
         <a href=\"" . $imgdir . $a_img[$x] ."\">
            <img src=\"" . $imgdir . $a_img[$x] . "\" width=\"120\" border=\"0\"/> </a>
<input type='checkbox' name='images' value='1' />$img = end(explode('/', $a_img[$x]));

      </td>

mas assim, a frente da checkbox, aparece:

= end(explode('/', 001.JPG));

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...

Important Information

By using this site you accept our Terms of Use and Privacy Policy. We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.