Programación Web y Scripting > PHP

 Problema Al Borrar Imágenes

<< < (3/4) > >>

zaida20:
Hola de nuevo, he cambiado el código:


--- Código: Text ---else//viene de examinar{   if(&#036;ruta_imagen!=NULL)  {    &#036;i=0;    &#036;x=0;    if(&#036;_SESSION['foto']==NULL)//si la sesión no existe, entra por primera vez    {      &#036;barra=stripslashes(&#036;ruta_imagen);      &#036;size=@getimagesize(&#036;barra);      if(&#036;size==true)      {        &#036;rut=array();        &#036;rutimagen[0]=&#036;barra;        &#036;_SESSION['foto']=&#036;rutimagen;        &#036;popo=&#036;_SESSION['foto'];        &#036;ancho=60;        &#036;alto[0]=&#036;size[1]/(&#036;size[0]/&#036;ancho);      }      else      {        &#036;error=2;        &#036;popo=&#036;_SESSION['foto'];      }    }    else//entra por segunda vez, la sesión existe    {      &#036;barra=stripslashes(&#036;ruta_imagen);      &#036;imagenes=&#036;_SESSION['foto'];      if(&#036;imagenes[&#036;i]!=&#036;barra)//la imagen es distinta de la ruta, la metemos en sesion      {        while(&#036;imagenes[&#036;i]!=NULL)//si la imagen es distinta de null        {          &#036;size=@getimagesize(&#036;imagenes[&#036;i]);          if(&#036;size==true)          {            &#036;num=count(&#036;imagenes);            &#036;ancho=60;            &#036;alto[&#036;i]=&#036;size[1]/(&#036;size[0]/&#036;ancho);            &#036;rutimagen=&#036;imagenes;            &#036;rutimagen[&#036;num]=&#036;barra;            &#036;_SESSION['foto']=&#036;rutimagen;            &#036;popo=&#036;_SESSION['foto'];            //break;          }          else//si la foto está dañada          {            &#036;error=1;            &#036;popo=&#036;_SESSION['foto'];            break;          }          &#036;i++;        }        &#036;nueva_imagen=&#036;_SESSION['foto'];        while(&#036;nueva_imagen[&#036;x]!=NULL)        {          &#036;size=@getimagesize(&#036;nueva_imagen[&#036;x]);          &#036;ancho=60;          &#036;alto[&#036;x]=&#036;size[1]/(&#036;size[0]/&#036;ancho);          &#036;x++;        }      }      else//si existe la foto      {        &#036;error=2;        &#036;popo=&#036;_SESSION['foto'];      }      }  }}  

La primera parte la hace correctamente(cuando la sesión no existe), el problema viene cuando elijo una imagen dañada, no entra dónde el error, me visualiza el espacio de la imagen que está dañada.

¿Podeís ayudarme?

Saludos y gracias :hola:

zaida20:
De nuevo he realizado modificaciones en el código, éste es el código completo:


--- Código: Text ---&#60;?phpsession_start();&#036;ruta_imagen=&#036;_GET['ruta'];&#036;borrar=&#036;_GET['foto_borrar'];&#036;barra=stripslashes(&#036;borrar);if(&#036;barra!=NULL)//viene de borrar{  //echo &#036;barra;//ruta a eliminar  &#036;imagenes=&#036;_SESSION['foto'];  //print_r(&#036;imagenes);//array que tenemos antes de borrar nada  &#036;i=0;  &#036;j=0;  while(&#036;imagenes[&#036;j]!=NULL)  {    if(&#036;imagenes[&#036;j]!=&#036;barra)    {      &#036;imagenes_a[&#036;i]=&#036;imagenes[&#036;j];      &#036;i++;    }    &#036;j++;  }  //print_r (&#036;imagenes_a);//array en el que ya has eliminado lo que trae &#036;borrar  &#036;imagenes=&#036;imagenes_a;  &#036;_SESSION['foto']=&#036;imagenes;  &#036;popo=&#036;_SESSION['foto'];}else//viene de examinar{   if(&#036;ruta_imagen!=NULL)  {    &#036;i=0;    &#036;x=0;    if(&#036;_SESSION['foto']==NULL)//si la sesión no existe, entra por primera vez    {      &#036;barra=stripslashes(&#036;ruta_imagen);      &#036;size=@getimagesize(&#036;barra);      if(&#036;size==true)      {        &#036;rut=array();        &#036;rutimagen[0]=&#036;barra;        &#036;_SESSION['foto']=&#036;rutimagen;        &#036;popo=&#036;_SESSION['foto'];        &#036;ancho=60;        &#036;alto[0]=&#036;size[1]/(&#036;size[0]/&#036;ancho);      }      else      {        &#036;error=2;        &#036;popo=&#036;_SESSION['foto'];      }    }    else//entra por segunda vez, la sesión existe    {      &#036;imagenes=&#036;_SESSION['foto'];      &#036;barra=stripslashes(&#036;ruta_imagen);      &#036;size=@getimagesize(&#036;barra);      echo &#036;size;      if(&#036;size==true)      {        while(&#036;imagenes[&#036;i]!=NULL)//si la imagen es distinta de null        {          if(&#036;imagenes[&#036;i]!=&#036;barra)//la imagen es distinta de la ruta, la metemos en sesion          {            &#036;num=count(&#036;imagenes);            &#036;ancho=60;            &#036;alto[&#036;i]=&#036;size[1]/(&#036;size[0]/&#036;ancho);            &#036;rutimagen=&#036;imagenes;            &#036;rutimagen[&#036;num]=&#036;barra;            &#036;_SESSION['foto']=&#036;rutimagen;            &#036;popo=&#036;_SESSION['foto'];            //break;          }          else//si existe la foto          {            &#036;error=1;            &#036;popo=&#036;_SESSION['foto'];            break;          }        &#036;i++;        }        &#036;nueva_imagen=&#036;_SESSION['foto'];        while(&#036;nueva_imagen[&#036;x]!=NULL)        {          &#036;size=@getimagesize(&#036;nueva_imagen[&#036;x]);          &#036;ancho=60;          &#036;alto[&#036;x]=&#036;size[1]/(&#036;size[0]/&#036;ancho);          &#036;x++;        }      }      else//si está dañada      {        &#036;error=2;        &#036;popo=&#036;_SESSION['foto'];      }      }  }}?&#62;  

Los problemas que tengo ahora es que cuando elijo una imagen dañada o que ya se está visualizando se ocultan las que se están mostrando.
El otro problema es que cuando estoy visualizando tres imágenes, al meter la cuarta no me valida si ya se está visualizando o no la imagen, directamente la agrega a la lista de visualización.

Espero podais ayudarme, gracias y saludos  :hola:

Avalon:
Hola. Podrías adjuntar el código del documento HTML que llama a ese script?

Salu2,
Avalon

zaida20:
Aquí lo tienes:


--- Código: Text --- &#60;html&#62;&#60;link href=&#34;../../estilo.css&#34; rel=&#34;stylesheet&#34; rev=&#34;stylesheet&#34; type=&#34;text/css&#34;&#62;&#60;script&#62;function mostrar_iframe(){  parent.document.getElementById('iframe_grande').style.display=&#34;block&#34;;}&#60;/script&#62;&#60;body bgcolor=&#34;#EDE4E4&#34; leftmargin=&#34;0&#34; topmargin=&#34;0&#34;&#62;&#60;?phpif(&#036;_SESSION['foto']!=NULL){?&#62;&#60;table width=&#34;265&#34; height=&#34;80&#34; border=&#34;1&#34; cellpadding=&#34;0&#34; cellspacing=&#34;0&#34; bordercolor=&#34;#990000&#34;&#62;  &#60;tr&#62;    &#60;td height=&#34;80&#34; align=&#34;left&#34; valign=&#34;top&#34; bordercolor=&#34;#ded4d4&#34;&#62;       &#60;div class=&#34;barra&#34; id=&#34;scroll&#34; style=&#34;overflow:auto; width:260px; height:92px;&#34;&#62;         &#60;table border=&#34;1&#34; cellpadding=&#34;0&#34; cellspacing=&#34;0&#34; bordercolor=&#34;#ede4e4&#34;&#62;          &#60;tr&#62;             &#60;?php&#036;i=0;while(&#036;popo[&#036;i]!=NULL){?&#62;            &#60;td height=&#34;15&#34; style=&#34;border-top-color:#000000;border-left-color:#000000&#34;&#62;               &#60;div align=&#34;center&#34;&#62;&#60;a href=&#34;imagenes_blog.php?foto_borrar=&#60;?php echo &#036;popo[&#036;i]?&#62;&#34;&#62;&#60;img src=&#34;../../img/borrar_cesta.gif&#34; alt=&#34;Borrar&#34; width=&#34;15&#34; height=&#34;14&#34; style=&#34;border:solid 1px;border-color: #ede4e4;&#34;&#62;&#60;/a&#62;&#60;/div&#62;&#60;/td&#62;            &#60;td height=&#34;15&#34; style=&#34;border-top-color:#000000;border-right-color:#000000&#34;&#62;&#60;img src=&#34;../../img/ojo.gif&#34; alt=&#34;Ver a tama&ntilde;o real&#34; width=&#34;15&#34; height=&#34;15&#34; style=&#34;cursor:pointer&#34; onclick=&#34;mostrar_iframe(); parent.document.iframe_grande.location.href='imagenes_grande.php?imagen=&#60;?php echo &#036;popo[&#036;i]?&#62;'&#34;&#62;&#60;/td&#62;            &#60;td width=&#34;10&#34; rowspan=&#34;2&#34; valign=&#34;middle&#34; bordercolor=&#34;#ede4e4&#34;&#62; &#60;/td&#62;            &#60;?php&#036;i++;}?&#62;          &#60;/tr&#62;          &#60;tr&#62;             &#60;?php&#036;i=0;while(&#036;popo[&#036;i]!=NULL){  ?&#62;            &#60;td colspan=&#34;2&#34; valign=&#34;top&#34; style=&#34;border-left-color:#000000;border-right-color:#000000;border-bottom-color:#000000&#34;&#62; &#60;div align=&#34;center&#34;&#62;&#60;img src=&#34;&#60;?php echo &#036;popo[&#036;i]; ?&#62;&#34; width=&#34;&#60;?php echo &#036;ancho; ?&#62;&#34;  height=&#34;&#60;?php echo &#036;alto[&#036;i]; ?&#62;&#34; &#62;&#60;/div&#62;&#60;/td&#62;            &#60;?php&#036;i++;}?&#62;          &#60;/tr&#62;        &#60;/table&#62;      &#60;/div&#62;&#60;/td&#62;  &#60;/tr&#62;&#60;/table&#62;&#60;?phpif(&#036;error==2){?&#62;&#60;table width=&#34;266&#34; border=&#34;0&#34; cellspacing=&#34;0&#34; cellpadding=&#34;0&#34;&#62;  &#60;tr&#62;     &#60;td&#62;&#60;?php echo &#34;La imagen está dañada, por favor, elija otra&#34;; ?&#62;&#60;/td&#62;  &#60;/tr&#62;&#60;/table&#62;&#60;?php}?&#62;&#60;?phpif(&#036;error==1){?&#62;&#60;table width=&#34;266&#34; border=&#34;0&#34; cellspacing=&#34;0&#34; cellpadding=&#34;0&#34;&#62;  &#60;tr&#62;     &#60;td&#62;&#60;?php echo &#34;La imagen ya existe, por favor, elija otra&#34;; ?&#62;&#60;/td&#62;  &#60;/tr&#62;&#60;/table&#62;&#60;?php}}else{?&#62;&#60;script&#62;parent.document.getElementById('foto').value=&#34;&#34;;&#60;/script&#62;&#60;?php}?&#62;&#60;/body&#62;&#60;/html&#62; 
Gracias y saludos :hola:

zaida20:
De nuevo cambié el código:

éste trozo:

--- Código: Text --- &#036;imagenes=&#036;_SESSION['foto'];      &#036;barra=stripslashes(&#036;ruta_imagen);            while(&#036;imagenes[&#036;i]!=NULL)//si la imagen es distinta de null      {        if(&#036;imagenes[&#036;i]!=&#036;barra)//la imagen es distinta de la ruta, la metemos en sesion        {          &#036;num=count(&#036;imagenes);          &#036;rutimagen=&#036;imagenes;          &#036;rutimagen[&#036;num]=&#036;barra;          &#036;_SESSION['foto']=&#036;rutimagen;          &#036;popo=&#036;_SESSION['foto'];          break;        }  
por éste;


--- Código: Text ---      &#036;fotos=&#036;_SESSION['foto'];      &#036;barra=stripslashes(&#036;ruta_imagen);      &#036;size=@getimagesize(&#036;barra);      if(&#036;size==true)      {        &#036;num=count(&#036;fotos);        &#036;rutimagen=&#036;fotos;        &#036;rutimagen[&#036;num]=&#036;barra;        &#036;_SESSION['foto']=&#036;rutimagen;        &#036;existe=in_array(&#036;barra,&#036;rutimagen);        if(&#036;existe==true)//existe por lo que borramos        {          &#036;contador=count(&#036;rutimagen);          &#036;i=0;          while(&#036;i&#60;&#036;contador)          {            &#036;rutimagen_a[&#036;i]=&#036;rutimagen[&#036;i];            &#036;i++;          }        }        print_r(&#036;rutimagen);        echo&#34;&#60;br&#62;&#34;;              print_r(&#036;rutimagen_a);          

Pero tampoco funciona, me mete la imagen repetida.
Gracias y saludos :hola:

Navegación

[0] Índice de Mensajes

[#] Página Siguiente

[*] Página Anterior

Ir a la versión completa