Foros del Web » Programando para Internet » PHP »

Añadir boton imagen

Estas en el tema de Añadir boton imagen en el foro de PHP en Foros del Web. hola bueno queria saber si alguien me puede dar una mano en como poner un boton como este para que pueda agregar imagenes a mi ...
  #1 (permalink)  
Antiguo 26/01/2012, 19:17
Avatar de vicion  
Fecha de Ingreso: noviembre-2011
Mensajes: 79
Antigüedad: 12 años, 5 meses
Puntos: 1
Añadir boton imagen

hola bueno queria saber si alguien me puede dar una mano en como poner un boton como este para que pueda agregar imagenes a mi post ya q por ahora solo puedo publicar texto.

este es mi codigo:
Código PHP:
Ver original
  1. <?php
  2. header("Content-Type: text/html;charset=utf-8");
  3. // incluimos el archivo de conexion
  4. include ('conexion.php');
  5. // recibimos el formulario
  6. if(isset($_POST['enviar']) && $_POST['enviar'] == 'Enviar'){
  7. // comprobamos que el formulario no envie campos vacios
  8. if(!empty($_POST['notTitulo']) && $_POST['notTexto'] &&
  9. $_POST['notCategoriaID']){
  10. // creamos las variables y les asignamos los valores a insertar
  11. $notTitulo = $_POST['notTitulo'];
  12. $notTexto = $_POST['notTexto'];
  13. $notCategoriaID = $_POST['notCategoriaID'];
  14. // hacemos el INSERT en la BD
  15. $sqlInsertNot = mysql_query("INSERT INTO notiblog
  16. (notTitulo, notTexto, notCategoriaID)
  17. VALUES ('$notTitulo', '$notTexto', '$notCategoriaID')",
  18. $db_link) or die(mysql_error());
  19. // enviamos un mensaje de exito
  20. echo "Los datos fueron gurdados correctamente";
  21. }else{
  22. // si el formulario envia algun campo vacio
  23. // enviamos un mensaje de error
  24. echo "Debe llenar todos los campos del formulario";
  25. }
  26. }
  27. ?>
  28. <!-- el formulario -->
  29. <form name="noticia" action="<?php $_SERVER['PHP_SELF']; ?>" method="post">
  30. <p>
  31. Título de la Noticia<br />
  32. <input type="text" name="notTitulo" size="50" />
  33. </p>
  34. <p>
  35. Texto de la Noticia<br />
  36. <textarea name="notTexto" rows="10" cols="50"></textarea>
  37. </p>
  38. <p>
  39. Categoría<br />
  40. <select name="notCategoriaID">
  41. <option value="">Escoger de la Lista</option>
  42. <?php
  43. // asignamos una categoria a la noticia
  44. // mediante un select
  45. $sqlQueryCat = mysql_query("SELECT * FROM caterina", $db_link)
  46. // creamos un bucle while
  47. // que nos muestre todas las categorias
  48. // que tenemos guardadas en la BD
  49. while($rowCat = mysql_fetch_array($sqlQueryCat)){
  50. echo "<option value='$rowCat[cat_ID]'>$rowCat[catCategoria]</option>";
  51. }
  52. ?>
  53. </select>
  54. </p>
  55. <p>
  56. <input type="submit" name="enviar" value="Enviar" />
  57. </p>
  58. </form>
  #2 (permalink)  
Antiguo 26/01/2012, 19:30
Avatar de geeck22  
Fecha de Ingreso: agosto-2010
Ubicación: Tijuana B.C.
Mensajes: 79
Antigüedad: 13 años, 8 meses
Puntos: 7
Respuesta: Añadir boton imagen

sencillo, primero crea el boton y con un poco de javascript configuralo para que al pinchar clic agrege [img] [/img]o algo por el estilo a tu textarea Ó que abra una ventana del navegador preguntando la url de la imagen.
en cualquiera de los dos casos la url de la imagen ira dentro de esas dos etiquetas.

una vez tengas este texto como un post o get en tu formulario remplazas [img] con str remplace por: ' <img src=" ' y [/img] asi: ' " /> ' de modo que cuando lo guardes en la bd se guarde como <img src="url.com/imagen.jpg" /> y aparesca en tu post

Espero haberte ayudado.
PD: este ejemplo seria en el caso de una imagen externa
__________________
Si te ayudo mi respuesta, dale clic en "Me gustó, ¡gracias!", nada te cuesta :)
  #3 (permalink)  
Antiguo 26/01/2012, 19:31
Avatar de geeck22  
Fecha de Ingreso: agosto-2010
Ubicación: Tijuana B.C.
Mensajes: 79
Antigüedad: 13 años, 8 meses
Puntos: 7
Respuesta: Añadir boton imagen

tambien puedes descargar aplicaciones prediseñadas como la herramienta de post de este mismo foro y lo configuras para qe valla con tu web, yo hace mucho hice una aplicacion de estas porque ninguna era como yo la queria, batalle muchisimo e igual perdi el codigo, si no te lo pasaba ;)

esto se llama bbcode
__________________
Si te ayudo mi respuesta, dale clic en "Me gustó, ¡gracias!", nada te cuesta :)
  #4 (permalink)  
Antiguo 26/01/2012, 19:37
Avatar de vicion  
Fecha de Ingreso: noviembre-2011
Mensajes: 79
Antigüedad: 12 años, 5 meses
Puntos: 1
Respuesta: Añadir boton imagen

lo voy a buscar como bbcode entonces!! gracias por responder!!!
Saludos!! si por las dudas encuentras el codigo o algo parecido te lo agradeceria de corazon
  #5 (permalink)  
Antiguo 26/01/2012, 19:54
Avatar de geeck22  
Fecha de Ingreso: agosto-2010
Ubicación: Tijuana B.C.
Mensajes: 79
Antigüedad: 13 años, 8 meses
Puntos: 7
Respuesta: Añadir boton imagen

estas de suerte, lo encontre en un usb ;D
ahi te va el codigo
bbcode.php
Código PHP:
<?php
function bbcode($texto) {
    
$texto nl2br($texto);
    
$textostripslashes($texto);
    
$texto str_replace("[codigo]"'Codigo:<br><div style="background-color:#FFFFFF; margin: 0px; padding: 6px; border: 1px inset; width: 645px; text-align: left; overflow: auto">[codigo]'$texto);
    
$texto str_replace("[/codigo]""[/codigo]</div>"$texto);
     
$texto str_replace('&quot;','"',$texto); 
    
$simple_search = array(
'/\[\:\)\]/is',
'/\[\:\(\]/is',
'/\[\;\)\]/is',
'/\[&lt;3\]/is',
'/\[\:D\]/is',
'/\[B\)]/is',
'/\[\:P\]/is',
'/\[\:O\]/is',
'/\[O\;\]/is',
'/\[Y]/is',
'/\[N]/is',
'/\[\:S\]/is',
'/\[\:\|\]/is',
'/\[x3]/is',
'/\[\:\*\]/is',
'/\:idiot\:/is',
'/\:hahaha\:/is',
'/\:aplauso\:/is',
'/\:olle:/is',
'/\:zzz\:/is',
'/\:blah\:/is',
'/\:banana\:/is',
'/\:getalife\:/is',
'/\[cita\](.*?)\[\/cita\]/is',
'/\[b\](.*?)\[\/b\]/is',
'/\[i\](.*?)\[\/i\]/is',
'/\[u\](.*?)\[\/u\]/is',
'/\[link\](.*?)\[\/link\]/is',
'#\[codigo\](.*?)\[\/codigo\]#se',
'/\[youtube\](.*?)\[\/youtube\]/is',
'/\[img\=chica](.*?)\[\/img]/is',
'/\[img\=mediana](.*?)\[\/img]/is',
'/\[img\=grande](.*?)\[\/img]/is',
'/\[center\](.*?)\[\/center\]/is',
'/\[left\](.*?)\[\/left\]/is',
'/\[right\](.*?)\[\/right\]/is',
'/\[justify\](.*?)\[\/justify\]/is',
'/\[lista\-punto\](.*?)\[\/lista\-punto\]/is'
); 
    
$simple_replace = array(
'<img src="http://tuweb.com/bbcode/emoticons/).gif">',
'<img src="http://tuweb.com/bbcode/emoticons/(.gif">',
'<img src="http://tuweb.com/bbcode/emoticons/;).gif">',
'<img src="http://tuweb.com/bbcode/emoticons/3.gif">',
'<img src="http://tuweb.com/bbcode/emoticons/D.gif">',
'<img src="http://tuweb.com/bbcode/emoticons/BD.gif">',
'<img src="http://tuweb.com/bbcode/emoticons/P.gif">',
'<img src="http://tuweb.com/bbcode/emoticons/o.gif">',
'<img src="http://tuweb.com/bbcode/emoticons/o;.gif">',
'<img src="http://tuweb.com/bbcode/emoticons/Y.gif">',
'<img src="http://tuweb.com/bbcode/emoticons/N.gif">',
'<img src="http://tuweb.com/bbcode/emoticons/s.gif">',
'<img src="http://tuweb.com/bbcode/emoticons/l.gif">',
'<img src="http://tuweb.com/bbcode/emoticons/x3.gif">',
'<img src="http://tuweb.com/bbcode/emoticons/B).gif">',
'<img src="http://tuweb.com/bbcode/emoticons/idiot.gif">',
'<img src="http://tuweb.com/bbcode/emoticons/lol.gif">',
'<img src="http://tuweb.com/bbcode/emoticons/aplauso.gif">',
'<img src="http://tuweb.com/bbcode/emoticons/olle.gif">',
'<img src="http://tuweb.com/bbcode/emoticons/zzz.gif">',
'<img src="http://tuweb.com/bbcode/emoticons/blah.gif">',
'<img src="http://tuweb.com/bbcode/emoticons/banana.gif">',
'<img src="http://tuweb.com/bbcode/emoticons/getalife.gif">',
'<blockquote>Cita:<br><table style="background-color:#E8E8E8; border:solid 1px #000000; border-left: solid 5px; padding: 5px;"><tr><td width="400">$1</td></tr></table></blockquote>',
'<span style="font-weight:bold">$1</span>',
'<span style="font-style:italic">$1</span>',
'<span style="text-decoration:underline">$1</span>',
'<a href=$1 target="_blank">$1</a>',
"highlight_string(stripslashes(html_entity_decode(str_replace('<br />','','$1'))), true)",
'<iframe title="YouTube video player" width="640" height="390" src="http://www.youtube.com/embed/$1" frameborder="0" allowfullscreen></iframe>',
'<img width="320" src="$1">',
'<img width="480" src="$1">',
'<img width="640" src="$1">',
'<div style="text-align: center;">$1</div>',
'<div style="text-align: left;">$1</div>',
'<div style="text-align: right;">$1</div>',
'<div style="text-align: justify;">$1</div>',
'<li>$1</li>'
);
$texto preg_replace ($simple_search$simple_replace$texto); 
return 
$texto
}
?>
__________________
Si te ayudo mi respuesta, dale clic en "Me gustó, ¡gracias!", nada te cuesta :)
  #6 (permalink)  
Antiguo 26/01/2012, 19:54
Avatar de geeck22  
Fecha de Ingreso: agosto-2010
Ubicación: Tijuana B.C.
Mensajes: 79
Antigüedad: 13 años, 8 meses
Puntos: 7
Respuesta: Añadir boton imagen

bbcode.js
Código Javascript:
Ver original
  1. function instag(tag){
  2. var input = document.form1.textarea;
  3. if(typeof document.selection != 'undefined' && document.selection) {
  4. var str = document.selection.createRange().text;
  5. input.focus();
  6. var sel = document.selection.createRange();
  7. sel.text = "[" + tag + "]" + str + "[/" +tag+ "]";
  8. sel.select();
  9. return;
  10. }
  11. else if(typeof input.selectionStart != 'undefined'){
  12. var start = input.selectionStart;
  13. var end = input.selectionEnd;
  14. var insText = input.value.substring(start, end);
  15. input.value = input.value.substr(0, start) + '['+tag+']' + insText + '[/'+tag+']'+ input.value.substr(end);
  16. input.focus();
  17. input.setSelectionRange(start+2+tag.length+insText.length+3+tag.length,start+2+tag.length+insText.length+3+tag.length);
  18. return;
  19. }
  20. else{
  21. input.value+=' ['+tag+'][/'+tag+']';
  22. return;
  23. }
  24. }
  25. function insicon(icon){
  26. var input = document.form1.textarea;
  27. if(typeof document.selection != 'undefined' && document.selection) {
  28. var str = document.selection.createRange().text;
  29. input.focus();
  30. var sel = document.selection.createRange();
  31. sel.text = "[" + icon + "]";
  32. sel.select();
  33. return;
  34. }
  35. else if(typeof input.selectionStart != 'undefined'){
  36. var start = input.selectionStart;
  37. var end = input.selectionEnd;
  38. var insText = input.value.substring(start, end);
  39. input.value = input.value.substr(0, start) + '['+icon+']' + input.value.substr(end);
  40. input.focus();
  41. input.setSelectionRange(start+2+tag.length+insText.length+3+tag.length,start+2+tag.length+insText.length+3+tag.length);
  42. return;
  43. }
  44. else{
  45. input.value+=' ['+icon+'] ';
  46. return;
  47. }
  48. }function inscara(cara){
  49. var input = document.form1.textarea;
  50. if(typeof document.selection != 'undefined' && document.selection) {
  51. var str = document.selection.createRange().text;
  52. input.focus();
  53. var sel = document.selection.createRange();
  54. sel.text = ":" + cara + ":";
  55. sel.select();
  56. return;
  57. }
  58. else if(typeof input.selectionStart != 'undefined'){
  59. var start = input.selectionStart;
  60. var end = input.selectionEnd;
  61. var insText = input.value.substring(start, end);
  62. input.value = input.value.substr(0, start) + ':'+cara+':' + input.value.substr(end);
  63. input.focus();
  64. input.setSelectionRange(start+2+tag.length+insText.length+3+tag.length,start+2+tag.length+insText.length+3+tag.length);
  65. return;
  66. }
  67. else{
  68. input.value+=' :'+cara+': ';
  69. return;
  70. }
  71. }
  72. function inslink(){
  73. var input = document.form1.textarea;
  74. if(typeof document.selection != 'undefined' && document.selection) {
  75. var str = document.selection.createRange().text;
  76. input.focus();
  77. var my_link = prompt("Ingresar URL:","http://");
  78. if (my_link != null) {
  79. if(str.length==0){
  80. str=my_link;
  81. }
  82. var sel = document.selection.createRange();
  83. sel.text = "[link]" + str + "[/link]";
  84. sel.select();
  85. }
  86. return;
  87. }else if(typeof input.selectionStart != 'undefined'){
  88. var start = input.selectionStart;
  89. var end = input.selectionEnd;
  90. var insText = input.value.substring(start, end);
  91. var my_link = prompt("Ingresa la URL:","http://");
  92. if (my_link != null) {
  93. if(insText.length==0){
  94. insText=my_link;
  95. }
  96. input.value = input.value.substr(0, start) +"[link]" + insText + "[/link]"+ input.value.substr(end);
  97. input.focus();
  98. input.setSelectionRange(start+11+my_link.length+insText.length+4,start+11+my_link.length+insText.length+4);
  99. }
  100. return;
  101. }else{
  102. var my_link = prompt("Ingresar URL:","http://");
  103. var my_text = prompt("Ingresar el texto del link:","");
  104. input.value+=" [link]" + my_text + "[/link]";
  105. return;
  106. }
  107. }
  108. function insimgch(){
  109. var input = document.form1.textarea;
  110. if(typeof document.selection != 'undefined' && document.selection) {
  111. var str = document.selection.createRange().text;
  112. input.focus();
  113. var my_link = prompt("Ingresar URL de la Imagen chica:","http://");
  114. if (my_link != null) {
  115. if(str.length==0){
  116. str=my_link;
  117. }
  118. var sel = document.selection.createRange();
  119. sel.text = "[img=chica]" + str + "[/img]";
  120. sel.select();
  121. }
  122. return;
  123. }else if(typeof input.selectionStart != 'undefined'){
  124. var start = input.selectionStart;
  125. var end = input.selectionEnd;
  126. var insText = input.value.substring(start, end);
  127. var my_link = prompt("Ingresa la URL de la Imagen chica:","http://");
  128. if (my_link != null) {
  129. if(insText.length==0){
  130. insText=my_link;
  131. }
  132. input.value = input.value.substr(0, start) +"[img=chica]" + insText + "[/img]"+ input.value.substr(end);
  133. input.focus();
  134. input.setSelectionRange(start+11+my_link.length+insText.length+4,start+11+my_link.length+insText.length+4);
  135. }
  136. return;
  137. }else{
  138. var my_link = prompt("Ingresar URL de la Imagen chica:","http://");
  139. var my_text = prompt("Ingresar URL de la Imagen chica:","");
  140. input.value+=" [img=chica]" + my_text + "[/img]";
  141. return;
  142. }
  143. }
  144.  
  145. function insimgmd(){
  146. var input = document.form1.textarea;
  147. if(typeof document.selection != 'undefined' && document.selection) {
  148. var str = document.selection.createRange().text;
  149. input.focus();
  150. var my_link = prompt("Ingresar URL de la Imagen mediana:","http://");
  151. if (my_link != null) {
  152. if(str.length==0){
  153. str=my_link;
  154. }
  155. var sel = document.selection.createRange();
  156. sel.text = "[img=mediana]" + str + "[/img]";
  157. sel.select();
  158. }
  159. return;
  160. }else if(typeof input.selectionStart != 'undefined'){
  161. var start = input.selectionStart;
  162. var end = input.selectionEnd;
  163. var insText = input.value.substring(start, end);
  164. var my_link = prompt("Ingresa la URL de la Imagen mediana:","http://");
  165. if (my_link != null) {
  166. if(insText.length==0){
  167. insText=my_link;
  168. }
  169. input.value = input.value.substr(0, start) +"[img=mediana]" + insText + "[/img]"+ input.value.substr(end);
  170. input.focus();
  171. input.setSelectionRange(start+11+my_link.length+insText.length+4,start+11+my_link.length+insText.length+4);
  172. }
  173. return;
  174. }else{
  175. var my_link = prompt("Ingresar URL de la Imagen mediana:","http://");
  176. var my_text = prompt("Ingresar URL de la Imagen mediana:","");
  177. input.value+=" [img=mediana]" + my_text + "[/img]";
  178. return;
  179. }
  180. }
  181.  
  182. function insimggd(){
  183. var input = document.form1.textarea;
  184. if(typeof document.selection != 'undefined' && document.selection) {
  185. var str = document.selection.createRange().text;
  186. input.focus();
  187. var my_link = prompt("Ingresar URL de la Imagen grande:","http://");
  188. if (my_link != null) {
  189. if(str.length==0){
  190. str=my_link;
  191. }
  192. var sel = document.selection.createRange();
  193. sel.text = "[img=grande]" + str + "[/img]";
  194. sel.select();
  195. }
  196. return;
  197. }else if(typeof input.selectionStart != 'undefined'){
  198. var start = input.selectionStart;
  199. var end = input.selectionEnd;
  200. var insText = input.value.substring(start, end);
  201. var my_link = prompt("Ingresa la URL de la Imagen grande:","http://");
  202. if (my_link != null) {
  203. if(insText.length==0){
  204. insText=my_link;
  205. }
  206. input.value = input.value.substr(0, start) +"[img=grande]" + insText + "[/img]"+ input.value.substr(end);
  207. input.focus();
  208. input.setSelectionRange(start+11+my_link.length+insText.length+4,start+11+my_link.length+insText.length+4);
  209. }
  210. return;
  211. }else{
  212. var my_link = prompt("Ingresar URL de la Imagen grande:","http://");
  213. var my_text = prompt("Ingresar URL de la Imagen grande:","");
  214. input.value+=" [img=grande]" + my_text + "[/img]";
  215. return;
  216. }
  217. }
  218.  
  219. function insyt(){
  220. var input = document.form1.textarea;
  221. if(typeof document.selection != 'undefined' && document.selection) {
  222. var str = document.selection.createRange().text;
  223. input.focus();
  224. var my_link = prompt("Nota: el ID se extrae de la URL del video.\nEjemplo: http://www.youtube.com/watch?v= -> wTnsBP9u-TQ <-\nIngresar ID del video:","");
  225. if (my_link != null) {
  226. if(str.length==0){
  227. str=my_link;
  228. }
  229. var sel = document.selection.createRange();
  230. sel.text = "[youtube]" + str + "[/youtube]";
  231. sel.select();
  232. }
  233. return;
  234. }else if(typeof input.selectionStart != 'undefined'){
  235. var start = input.selectionStart;
  236. var end = input.selectionEnd;
  237. var insText = input.value.substring(start, end);
  238. var my_link = prompt("Nota: el ID se extrae de la URL del video.\nEjemplo: http://www.youtube.com/watch?v= -> wTnsBP9u-TQ <-\nIngresar ID del video:","");
  239. if (my_link != null) {
  240. if(insText.length==0){
  241. insText=my_link;
  242. }
  243. input.value = input.value.substr(0, start) +"[youtube]" + insText + "[/youtube]"+ input.value.substr(end);
  244. input.focus();
  245. input.setSelectionRange(start+11+my_link.length+insText.length+4,start+11+my_link.length+insText.length+4);
  246. }
  247. return;
  248. }else{
  249. var my_link = prompt("Nota: el ID se extrae de la URL del video.\nEjemplo: http://www.youtube.com/watch?v= -> wTnsBP9u-TQ <-\nIngresar ID del video:","");
  250. var my_text = prompt("Nota: el ID se extrae de la URL del video.\nEjemplo: http://www.youtube.com/watch?v= -> wTnsBP9u-TQ <-\nIngresar ID del video:","");
  251. input.value+=" [youtube]" + my_text + "[/youtube]";
  252. return;
  253. }
  254. }

en el head del documento donde este el formulario pones: <script src="bbcode/bbcode.js"></script>

y donde proceses el formulario le haces un include a bbcode: include("bbcode/bbcode.php");

y por ultimo le pasas el js a tu $_POST de esta manera: $post = bbcode($_POST['post']);
__________________
Si te ayudo mi respuesta, dale clic en "Me gustó, ¡gracias!", nada te cuesta :)
  #7 (permalink)  
Antiguo 26/01/2012, 19:55
Avatar de geeck22  
Fecha de Ingreso: agosto-2010
Ubicación: Tijuana B.C.
Mensajes: 79
Antigüedad: 13 años, 8 meses
Puntos: 7
Respuesta: Añadir boton imagen

ya solo te falta a ti agregar los botones y si gustas emoticones ;)

Recuerda.. no es perfecto mi codigo pero sirve! :P ya tiene tiempo asi qe no te fijes :A
__________________
Si te ayudo mi respuesta, dale clic en "Me gustó, ¡gracias!", nada te cuesta :)
  #8 (permalink)  
Antiguo 26/01/2012, 21:44
Avatar de vicion  
Fecha de Ingreso: noviembre-2011
Mensajes: 79
Antigüedad: 12 años, 5 meses
Puntos: 1
Respuesta: Añadir boton imagen

mil gracias la verdad!!
ahora me fijo bienn!!!
te comento como me fue!!!

mil gracias Saludos!!
Atención: Estás leyendo un tema que no tiene actividad desde hace más de 6 MESES, te recomendamos abrir un Nuevo tema en lugar de responder al actual.
Respuesta




La zona horaria es GMT -6. Ahora son las 19:33.