Saludos!
Quiero hacer una aplicación en la que cargues tu imagen desde tu disco duro y la puedas guardar en una BD, para luego verla, cambiarla o borrarla. La pregunta, es ¿Cómo la puedo guardar?
| |||
Ayuda con imagenes Saludos! Quiero hacer una aplicación en la que cargues tu imagen desde tu disco duro y la puedas guardar en una BD, para luego verla, cambiarla o borrarla. La pregunta, es ¿Cómo la puedo guardar? |
| ||||
Re: Ayuda con imagenes tenes que poner un campo file <input type="file"> el resto es programacion php. busca upload de imagenes con php. como para empezar http://www.desarrolloweb.com/articulos/1307.php saludos |
| ||||
Re: Ayuda con imagenes Cita: Aparte de eso, en form tienes que poner:
Iniciado por carlosmbrizuela ![]() tenes que poner un campo file <input type="file"> el resto es programacion php. busca upload de imagenes con php. como para empezar http://www.desarrolloweb.com/articulos/1307.php saludos
Código:
Y en el campo file, al menos el atributo name.enctype="multipart/form-data" Pero ya te digo, que el resto depende de como lo quieras hacer, subir la imagen como fichero o guardarla en la base de datos, que por lo general suele ser menos recomendable esto último. |
| |||
Re: Ayuda con imagenes Lo logré con una imagen, pero si quiero agregar 2 imagenes a la vez me marca el siguiente error: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '653d6b269289365795ba3e9d78be79ad.jpg'', cat_image2 = '4fcb019d7bc7fe69c37cc82873' at line 2 Este es mi código El formulario: <?php $sql = "SELECT cat_id, cat_image, cat_image2 FROM tbl_ubicacion WHERE cat_id = $pedidoIdG"; $result = dbQuery($sql); $row = dbFetchAssoc($result); extract($row); ?> <p> </p> <form action="processPedido.php?action=modify&catId=<?ph p echo $cat_id; ?>" method="post" enctype="multipart/form-data" name="frmCategory" id="frmCategory"> <table width="100%" border="0" align="center" cellpadding="5" cellspacing="1" class="entryTable"> <tr> <td width="150" class="label">Image</td> <td class="content"> <input name="fleImage" type="file" id="fleImage" class="box"> <?php if ($cat_image != '') { ?> <br> <img src="<?php echo WEB_ROOT . CATEGORY_IMAGE_DIR . $cat_image; ?>"> <a href="javascript:deleteImage(<?php echo $cat_id; ?>);">Borrar Imagen</a> <?php } ?> </td> </tr> <tr> <td width="150" class="label">Image</td> <td class="content"> <input name="fleImage2" type="file" id="fleImage2" class="box"> <?php if ($cat_image != '') { ?> <br> <img src="<?php echo WEB_ROOT . CATEGORY_IMAGE_DIR . $cat_image2; ?>"> <a href="javascript:deleteImage(<?php echo $cat_id; ?>);">Borrar Imagen</a> <?php } ?> </td> </tr> </table> <p align="center"> <input name="btnModify" type="button" id="btnModify" value="Agregar/Modificar" onClick="checkCategoryForm();" class="box"> <input name="btnCancel" type="button" id="btnCancel" value="Cancelar" onClick="window.location.href='index.php';" class="box"> </p> </form> y esta son las funciónes que encontré en un tutorial: /* Remove a category image */ function deleteImage() { if (isset($_GET['catId']) && (int)$_GET['catId'] > 0) { $catId = (int)$_GET['catId']; } else { header('Location: index.php'); } _deleteImage($catId); // update the image name in the database $sql = "UPDATE tbl_ubicacion SET cat_image = '' WHERE cat_id = $catId"; dbQuery($sql); header("Location: index.php?view=modify&catId=$catId"); } /* Delete a category image where category = $catId */ function _deleteImage($catId) { // we will return the status // whether the image deleted successfully $deleted = false; // get the image(s) $sql = "SELECT cat_image FROM tbl_ubicacion WHERE cat_id "; if (is_array($catId)) { $sql .= " IN (" . implode(',', $catId) . ")"; } else { $sql .= " = $catId"; } $result = dbQuery($sql); if (dbNumRows($result)) { while ($row = dbFetchAssoc($result)) { // delete the image file $deleted = @unlink(SRV_ROOT . CATEGORY_IMAGE_DIR . $row['cat_image']); } } return $deleted; } /* Upload an image and return the uploaded image name */ function uploadImage($inputName, $uploadDir) { $image = $_FILES[$inputName]; $imagePath = ''; // if a file is given if (trim($image['tmp_name']) != '') { // get the image extension $ext = substr(strrchr($image['name'], "."), 1); // generate a random new file name to avoid name conflict $imagePath = md5(rand() * time()) . ".$ext"; // check the image width. if it exceed the maximum // width we must resize it $size = getimagesize($image['tmp_name']); if ($size[0] > MAX_CATEGORY_IMAGE_WIDTH) { $imagePath = createThumbnail($image['tmp_name'], $uploadDir . $imagePath, MAX_CATEGORY_IMAGE_WIDTH); } else { // move the image to category image directory // if fail set $imagePath to empty string if (!move_uploaded_file($image['tmp_name'], $uploadDir . $imagePath)) { $imagePath = ''; } } } return $imagePath; } function modifyCategory() { $catId = (int)$_GET['catId']; //$name = $_POST['txtName']; //$description = $_POST['mtxDescription']; $image = $_FILES['fleImage']; $image2 = $_FILES['fleImage2']; $catImage = uploadImage('fleImage', SRV_ROOT . 'images/category/'); $catImage2 = uploadImage('fleImage2', SRV_ROOT . 'images/category2/'); // if uploading a new image // remove old image if ($catImage != '') { _deleteImage($catId); $catImage = "'$catImage'"; } else { // leave the category image as it was $catImage = 'cat_image'; } $sql = "UPDATE tbl_ubicacion SET cat_image = '$catImage', cat_image2 = '$catImage2' WHERE cat_id = $catId"; $result = dbQuery($sql) or die('Cannot update category. ' . mysql_error()); header('Location: index.php'); } Si le digo que no actualize cat_image2, entonces si funciona, si no me marca el error que les mencioné. |