DevilRocks92 Posted May 8, 2013 at 10:14 PM Report #506325 Posted May 8, 2013 at 10:14 PM Boa tarde, eu tenho uma tabela eventos: id_evento, evento_texto, evento_banner, evento_image, evento_cartaz, evento_idioma Para já faço o upload para o evento_banner e evento_image, pois sao a mesma imagem so altero o tamanho (o codigo esta dentro do <form>): <?php if(isset($_POST['Submit'])){ //Declara um Array para armazenar a mensagem de erro $error = array(); //se o nome for entregue if (empty($_POST['text'])){ $error[] = "text miss"; }else{ $text=$_POST['text']; } if (empty($_POST['cidade'])){ $error[] = "cidade"; }else{ $cidade=$_POST['cidade']; } if (empty($_FILES["file"]["name"])){ $error[] = "Choose an image for the band"; }else{ $image=$_FILES["file"]["name"]; } //send to Database if there's no error ' if (empty($error)) // If everything's OK... { $idioma=$_POST['idioma']; error_reporting(0); $change=""; $abc=""; define ("MAX_SIZE","2048"); function getExtension($str){ $i = strrpos($str,"."); if (!$i) { return ""; } $l = strlen($str) - $i; $ext = substr($str,$i+1,$l); return $ext; } $errors=0; if($_SERVER["REQUEST_METHOD"] == "POST") { $uploadedfile = $_FILES['file']['tmp_name']; if ($image) { $filename = stripslashes($_FILES['file']['name']); $extension = getExtension($filename); $extension = strtolower($extension); if (($extension != "jpg") && ($extension != "jpeg") && ($extension != "png") && ($extension != "gif")){ $change='<div class="notification n-error">Unknown Image extension </div> '; $errors=1; }else{ $size=filesize($_FILES['file']['tmp_name']); if ($size > MAX_SIZE*1024){ $change='<div class="notification n-error">You have exceeded the size limit!</div> '; $errors=1; } if($extension=="jpg" || $extension=="jpeg" ){ $uploadedfile = $_FILES['file']['tmp_name']; $src = imagecreatefromjpeg($uploadedfile); }else if($extension=="png"){ $uploadedfile = $_FILES['file']['tmp_name']; $src = imagecreatefrompng($uploadedfile); }else{ $src = imagecreatefromgif($uploadedfile); } echo $scr; list($width,$height)=getimagesize($uploadedfile); $newwidth=900; $newheight=($height/$width)*$newwidth; $tmp=imagecreatetruecolor($newwidth,$newheight); $newwidth1=300; $newheight1=($height/$width)*$newwidth1; $tmp1=imagecreatetruecolor($newwidth1,$newheight1); imagecopyresampled($tmp,$src,0,0,0,0,$newwidth,$newheight,$width,$height); imagecopyresampled($tmp1,$src,0,0,0,0,$newwidth1,$newheight1,$width,$height); $filename = "../../images/bands/". $_FILES['file']['name']; $file=explode(".".$extension, $_FILES['file']['name']); $filename1 = "../../images/bands/".$file[0]."_small".".".$extension; imagejpeg($tmp,$filename,100); imagejpeg($tmp1,$filename1,100); imagedestroy($src); imagedestroy($tmp); imagedestroy($tmp1); } } } //If no errors registred, print the success message if(!$errors) { $image=explode('../', $filename); $image1=explode('../', $filename1); $insert=("INSERT INTO eventos(evento_texto, evento_cidade, evento_banner, evento_image, evento_idioma) VALUES ('".$text."', '".$cidade."', '", '".$image[2]."', '".$image1[2]."', '".$idioma."')"); if(mysql_query($insert)){ header('Location: eventos.php'); } else{ echo '<div class="notification n-error">'.mysql_error().'.</div>'; } } else{ echo '<div class="notification n-error">The band already exists!</div>'; } }else{ //If the "error" array contains error msg , display them echo '<div class="notification n-error" <ul>'; foreach ($error as $key => $values) { echo '<li>'.$values.'</li>'; } echo '</ul></div>'; } } ?> O meu objectivo agora é adicionar uma imagem diferente no campo evento_cartaz. Será que me podem ajudar? Obrigado
hlourenco Posted May 9, 2013 at 07:14 PM Report #506502 Posted May 9, 2013 at 07:14 PM Para aceitar vários files num form é necessário ter o seguinte: <form method="POST" enctype="multipart/form-data"> <input type="file" name="files[]" multiple="multiple"> <input type="submit"> </form>'; Depois o $_FILES['files']['tmp_name'][0] passa a ter o 1º file e o $_FILES['files']['tmp_name'][1] o 2º ficheiro enviado. Espero que tenha ajudado.
HappyHippyHippo Posted May 9, 2013 at 07:30 PM Report #506510 Posted May 9, 2013 at 07:30 PM Para aceitar vários files num form é necessário ter o seguinte: <form method="POST" enctype="multipart/form-data"> <input type="file" name="files[]" multiple="multiple"> <input type="submit"> </form>'; Depois o $_FILES['files']['tmp_name'][0] passa a ter o 1º file e o $_FILES['files']['tmp_name'][1] o 2º ficheiro enviado. Espero que tenha ajudado. não obrigatoriamente: <form method="POST" enctype="multipart/form-data"> <input type="file" name="file1"> <input type="file" name="file2"> <input type="submit"> </form>'; $_FILES['file1']; $_FILES['file2']; IRC : sim, é algo que ainda existe >> #p@p Portugol Plus
hlourenco Posted May 9, 2013 at 08:06 PM Report #506520 Posted May 9, 2013 at 08:06 PM não obrigatoriamente: <form method="POST" enctype="multipart/form-data"> <input type="file" name="file1"> <input type="file" name="file2"> <input type="submit"> </form>'; $_FILES['file1']; $_FILES['file2']; Sim de acordo, e neste caso até é a solução mais adequada para o que o DevilRocks92 pretende.
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now