Jump to content

magcr23

Members
  • Posts

    80
  • Joined

  • Last visited

magcr23's Achievements

Member

Member (2/5)

0

Reputation

  1. magcr23

    echo

    That works fine, thx for the help mate
  2. magcr23

    echo

    Thx, you helped a lot. But how can i protect that? because if i use foreach( mysqli_real_escape_string($_POST['premio']) as $premio){ echo $premio . '<br />'; $query1 = mysqli_query($con, "INSERT INTO premio (idPremio, premio, idArtesao) VALUES (DEFAULT, '$premio', '$id')"); } The insert won't work
  3. magcr23

    echo

    Hi guys, i have that code (pag1.php): if(isset($_POST['btnQuantos'])){ $quant = limpa($_POST["quantos"]); $quantidade = $quant; echo '<form action="add.php" method="POST" ><br/>'; echo '<input type="hidden" name="txtID" id="txtID" value="'.$ln1['id'].'">'; for($i = 0; $i < $quantidade; $i++){ echo 'Premio ' . ($i + 1) . ' '; echo '<input type="text" name="premio" Placeholder="Prémio" /> <br/><br/>'; } echo '<input type="submit" name="btnPremio" id="btnPremio" value="Adicionar"><br/>'; echo '</form>'; } and that (add.php): $id = limpa($_POST['txtID']); $premio = limpa($_POST['premio']); echo $id; echo '<br/>'; echo '$premio'; The problem is that when i do echo '$premio' it only echo the last input, let's image that the user chosed 10 textbox, it will only echo the the last one. How can i make it echo all of them?
  4. So i have this security: check if it's an image, check if the file name already exist in the destiny folder. Is this enough? Or should i have more? If yes, wich?
  5. Yes i can see what you meen, explode won't work. I want to only allow jpg and png files, so-->$allowed = array('image/jpeg', 'image/png'); is this enough? or there are more mime tipes? like jpe....
  6. It's not a problem since i don't tried to do it. Why? Because to use getimagesize i need to allow the user to upload any file to my server. And if they can upload anything probably i will have problems in the future. So, what's the best option? Allow upload any file to then i can use getimagesize? Or try something like that: (it's just an idea, i'm not using it, that's a code for test, not to the website) $str = "AAA. BBB. CCC. DDD. EEE"; $exts = explode("." , $str); $contagem = count($exts); $a = $exts[$contagem-1]; //echo $a; if(!in_array($exts[$a], $allowed)){ ...
  7. It wasn't realy an bug but a stupid thing... The allowed extencions were all on UPPER CASE: @$allowed = array('PNG','JPEG','JPG'); when it should be: @$allowed = array('PNG','JPEG','JPG', 'png', jpeg', 'jpg'); Since it don't was an error but an forgetfulness of extensions it had no errors, i wasted 13h searching for an inixistent bug. But scootstah, explode is not the best option, but i think i'll not be able to use mime from getimagesize, so i was wondering, if there's an way to explode the last ".", i think that would work...
  8. I have an question, the gold in all verifications is to the user don't upload anything to my server right? But to use getimagesize the file need's to be on the server. (i have it on the code but it's not doing anything i belive). So, what should i do? Allow any file upload and then use getimagesize? Change $destination to the temporary folder? Or am i completly wrong and miss understod the function?? Btw: I've already found the bug that wasn't allowing the upload of some files.
  9. No errors, it just don't create the image, everything works fine less the image creation. If the extension is lower case it works, if it's UPPER CASE it returns empty CroNiX i know that i'm hidding them, i've already fixed them, it's only hided because it need to receive data from other page, and if the user just write on url the link to that page it will give some errors. Already tried what you said, and it gives me an extension error.
  10. Hi guys, I have this code: <head> <meta charset="utf-8"> </head> <body oncontextmenu="return false"> <?php include("conexao.php"); include("funcao.php"); @$id = limpa($_POST["id"]); @$preco = limpa($_POST["novopreco"]); @$descricao = mysql_real_escape_string($_POST["novodesc"]); @$data = date('Y-m-d'); //PASTA PARA MOVER OS FICHEIROS @$destination = "image/"; if(isset($_FILES['files2'])){ if(!empty($preco)){ // INSERIR DADOS NA BD $query2= "UPDATE casa SET preco = '$preco' WHERE id = '$id'"; mysqli_query($con, $query2); } if(!empty($descricao)){ // INSERIR DADOS NA BD $query2= "UPDATE casa SET descricao = '$descricao' WHERE id = '$id'"; mysqli_query($con, $query2); } foreach($_FILES['files2']['tmp_name'] as $key => $tmp_name){ //NOME DO FICHEIRO @$value = $_FILES['files2']['name'][$key]; //LISTA DE EXTENÇÕES PERMITIDAS @$allowed = array('PNG','JPEG','JPG'); //VER QUAL É A EXTENÇÃO @$exts = explode("." , $value); @$info = getimagesize($destination . $value); //SE A EXTENÇÃO DO FICHEIRO NÃO ESTIVER NA LISTA DAS PERMITIDAS if(@!in_array($exts[1], $allowed)){ //echo 'extensao invalida <br/>'; //print_r( 'Ficheiro-->' . $value . '<br/>Extencao-->' . @$exts[1] . '<br/>Apenas imagens sao permitidas'); }else{ //SE A EXTENÇÃO DO FICHEIRO ESTIVER NA LISTA DAS PERMITIDAS //echo 'Ficheiro valido<br/>'; $type = $_FILES['files2']['type'][$key]; $size = $_FILES['files2']['size'][$key]; $error = $_FILES['files2']['error'][$key]; $tmp_name = $_FILES['files2']['tmp_name'][$key]; /*-------------------------------------------------------------*/ //VARIAVEIS PARA ALTERAR NOME (adicionar um numero a frente(1,2,3,4,5...) $i = 1; $actual_name = pathinfo($value,PATHINFO_FILENAME); $original_name = $actual_name; $extension = pathinfo($value, PATHINFO_EXTENSION); /*-------------------------------------------------------------*/ //REDIMENSIONAR IMAGEM $uploadedfile = $tmp_name; if($extension=="jpg" || $extension=="jpeg" || $extension=="JPG" || $extension=="JPEG" ){ echo 'jpg -- '.$value; $src = imagecreatefromjpeg($uploadedfile); } if($extension=="png" || $extension=="PNG"){ echo 'png'; $src = imagecreatefrompng($uploadedfile); } list($width, $height) = getimagesize($uploadedfile); $newWidth = 500; $newHeight = ($width / $height) * $newWidth; // VERIFICAR SE É UMA IMAGEM VÁLIDA if($imageInfo = getimagesize($tmp_name)){ //MOVER FICHEIRO PARA PASTA DESTINO (image) if(file_exists("image/". $value)){ //SE O FICHEIRO JA EXISTE //echo 'existe<br/>'; while(file_exists('image/'.$actual_name.".".$extension)){ $actual_name = (string)$original_name.$i; $nome = $actual_name.".".$extension; $i++; } $tmp = imagecreatetruecolor($newWidth, $newHeight); imagecopyresampled($tmp, $src, 0,0,0,0, $newWidth, $newHeight, $width, $height); if($extension=="jpg" || $extension=="jpeg" || $extension=="JPG" || $extension=="JPEG" ){ imagejpeg($tmp, "image/". $nome, 100); } if($extension=="png" || $extension=="PNG"){ imagepng($tmp, "image/". $nome); } imagedestroy($src); imagedestroy($tmp); //move_uploaded_file($tmp_name,"image/".$nome); $query1 = mysqli_query($con, "INSERT INTO `imagem` (id, caminho, casa) VALUES (DEFAULT, '$nome', '$id')"); }else{ //SE O FICHEIRO NAO EXISTE //move_uploaded_file($tmp_name, "image/".$value); //CRIAR A IMAGEM $tmp = imagecreatetruecolor($newWidth, $newHeight); imagecopyresampled($tmp, $src, 0,0,0,0, $newWidth, $newHeight, $width, $height); if($extension=="jpg" || $extension=="jpeg" || $extension=="JPG" || $extension=="JPEG" ){ imagejpeg($tmp, "image/". $value, 100); } if($extension=="png" || $extension=="PNG"){ imagepng($tmp, "image/". $value); } imagedestroy($src); imagedestroy($tmp); // MOSTRA INFO DO FICHEIRO, SE FOR IMAGEM //print_r($imageInfo); $query1 = mysqli_query($con, "INSERT INTO `imagem` (id, caminho, casa) VALUES (DEFAULT, '$value', '$id')"); } } } } //header('Location: ver.php'); }else{ echo '<h1 style="color:red" align="center"><b>É necessario alterar algum condomínio!</b></h1>'; } include("fimConexao.php"); ?> </body> The problem is: If i try insert: jpg files --> it does JPG --> it don't The most awkward think is that i have the exact same code in other page and it works very well, in this page i get this error, why?
  11. HTML have any function to resize images? I was wondering if i could something like that: if(imgWidth != 500) or (imgHeight != 450){ resize image to width=500 height=450 } HTML can do that? Or will i need to use any script or external software?
  12. Yeah i've already fixed that xD I was copy and past from other files and i forgot to erase that xD
  13. I guys, i found a bug in the code. There's a link where you can see all my code--> http://justpaste.it/m6n5 When i upload multiple files, all the files get na same name. If i upload 1 file and there's a file already with that name it gets: name.jpg, name1.jpg, name2.jpg, name3.jpg... If i upload 2 files (even if there's no one with the same name) it will gets: file.jpg file.jpg file1.jpg file1.jpg file1.jpg file1.jpg file1.jpg file1.jpg ... it should be: file1.jpg file2.jpg file11.jpg file21.jpg file12.jpg file 22.jpg file13.jpg file 23.jpg ... What am i doing wrong?
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.