Requiero de un valioso apoyo de ustedes programadores avanzados, he logrado armar este codigo con FAQS de varios foros, es subir una imagen al servidor y cambiarle el tamaño a dicha imagen a un tamaño por defecto . pero no me sobreescribe la imagen si esta ya existe en la carpeta del servidor, arroja error !!! como puedo hacer para que me sobreescriba?
Código PHP:
Ver original
<?php include ("conexion.php"); $documento=$_SESSION['documento_user']; echo $documento; $dirbase = ''; $overwrite = "yes"; // Permitir sobreescritura? (yes/no) if ($HTTP_POST_FILES['MINIATURA']['name'] != '') { $nombre_archivo = $HTTP_POST_FILES['MINIATURA']['name']; $tipo_archivo = $HTTP_POST_FILES['MINIATURA']['type']; $tamano_archivo = $HTTP_POST_FILES['MINIATURA']['size']; $archivo = $archivo['filename']; //compruebo si las características del archivo son las que deseo $url_mini_no_valida = ''; $sw = ''; if ($sw == '') { $msj = 'Extensión de archivo no válida: '.$tipo_archivo; echo '<script> alert("Tipo de archivo no soportado: '.$msj.'"); </script>'; $tpl->assign($data); //$tpl->assign('ruta_miniatura', 'http://localhost/phpld22/miniaturas/'); $content = $tpl->fetch('admin/dir_links_edit.tpl'); $tpl->assign('content', $content); //Clean whitespace $tpl->load_filter('output', 'trimwhitespace'); //Make output echo $tpl->fetch('admin/main.tpl'); } else { if (move_uploaded_file($HTTP_POST_FILES['MINIATURA']['tmp_name'], $dirbase.'temp/'.$nombre_archivo)) { echo "fallo al borrar miniatura anterior"; } } escalar($dirbase.'temp/'.$nombre_archivo, 103,136); echo "fallo al borrar imagen original temporal"; } $data['MINIATURA'] = '_p'.$archivo.'.jpg'; } else { echo "Ocurrió algún error al subir el fichero. No pudo guardarse."; } } } function escalar($imagen,$ancho,$altura) { $prefijo_thumb = "_p"; $extension = $archivo['extension']; $nombre_archivo = $archivo['filename']; if (($extension == 'jpeg') || ($extension == 'jpg')) { } elseif ($extension == 'png') { } elseif ($extension == 'gif') { } if (!$img) { /* Comprobar si ha fallado */ $anchura = $ancho; //imagecopyresized ($thumb, $img, 0, 0, 0, 0, $anchura, $altura, $datos[0], $datos[1]); // rapidez } else { $ratio = ($datos[0] / $ancho); $ancho_final = $ancho; imagecopyresampled ($escalada, $img, 0, 0, 0, 0, $ancho_final, $alto_final, $datos[0], $datos[1]); // calidad //imagecopyresized ($thumb, $img, 0, 0, 0, 0, $anchura, $altura, $datos[0], $datos[1]); // rapidez $_POST['asd'] = 'http://www.minicio.com.ar/miniaturas/'.$prefijo_thumb.$nombre_archivo.'.jpg'; } } } ?> <!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> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Documento sin título</title> </head> <body> <form id="form1" name="form1" enctype="multipart/form-data" method="post" action=""> <label> <input type="file" name="MINIATURA" id="MINIATURA" /> </label> <p> <label> <input type="submit" name="enviar" id="enviar" value="Enviar" /> Porfavor para realizar la primera prueba descarga la "Imagen Original". </label> </p> </form> <table width="675" height="312" border="1"> <tr> <td width="329" height="33">Imagen Original: medias 300 x 300</td> <td width="330">Imagen Dimencionada: medias 310 x 250</td> </tr> <tr> <td height="228"><img src="http://www.minicio.com.ar/prueba.jpg" /></td> <td><img src="<?php echo $_POST['asd']; ?>"/></td> </tr> </table> </body> </html>
![sonriente](http://static.forosdelweb.com/fdwtheme/images/smilies/smile.png)