eu tenho aki um script que faz upload de uma imagem, cria um thumb e mete na base dados,
funciona tudo direitinho, mas agora encontrei um problema que são os caracteres especiais e os espacos do ficheiro
aki encontrei uma funcao que remove os caracteres e os espacos
<?php
function retirar_acentos_caracteres_especiais($string) {
$palavra = strtr($string, "ŠŒŽšœžŸ¥µÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖØÙÚÛÜÝßàáâãäåæçèéêëìíîïðñòóôõöøùúûüýÿ",
"SOZsozYYuAAAAAAACEEEEIIIIDNOOOOOOUUUUYsaaaaaaaceeeeiiiionoooooouuuuyy");
$palavranova = str_replace("_", " ", $palavra);
return $palavranova;
}
#Exemplo de uso
echo retirar_acentos_caracteres_especiais("¥µÀÁÂÃÄÅ");
?>
mas já tentei meter em todo o lado do meu script, mas nada funciona, nem o ficheiro nem a entrada na base dados , fica tudo como original
já tentei a funcao no $url, tambem no $_FILES['imagefile']['name']
alguém sabe o problema???
aki vai o meu codigo
foto.php
<?php
require_once("data/init.php");
print_header();
print_centro();
if(!empty($_GET["id"]))
{
$addfoto = $_GET["id"];
$tabela = "addfoto";
$k = 1;
$query = mysql_query("SELECT * FROM `$tabela` WHERE `id`='$k'");
$row = mysql_fetch_assoc($query);
if($row["id"])
{
$k = 1;
query("UPDATE `$tabela` SET `addfoto`='$addfoto' WHERE `id`='$k'");
$_SESSION["addfoto"] = $addfoto;
}
}
?>
<div id="primary">
<div id="content">
<spam><center>Escolha a imagem que deseja adicionar a noticia.</center></spam>
</div>
<!-- upload form -->
<div id="content">
<div class="box">
<?php
$idir = IDIR; //dir da img
$tdir = TDIR; //dir do thumb
// Maximum Width For Thumbnail Images
$twidth = TWIDTH; // Maximum Width For Thumbnail Images
$theight = THEIGHT; // Maximum Height For Thumbnail Images
if (!isset($_GET['subpage']))
{ // Image Upload Form Below ?>
<form method="post" action="foto.php?subpage=upload" enctype="multipart/form-data">
File:<br />
<input type="file" name="imagefile" class="form">
<br /><br />
<input name="submit" type="submit" value="Adicionar" class="form"> <input type="reset" value="Limpar" class="form">
</form>
<?php
}
else if (isset($_GET['subpage']) && $_GET['subpage'] == 'upload')
{ // Uploading/Resizing Script
$url = $_FILES['imagefile']['name']; // Set $url To Equal The Filename For Later Use
if ($_FILES['imagefile']['type'] == "image/jpg" || $_FILES['imagefile']['type'] == "image/jpeg" || $_FILES['imagefile']['type'] == "image/pjpeg")
{
$file_ext = strrchr($_FILES['imagefile']['name'], '.'); // Get The File Extention In The Format Of , For Instance, .jpg, .gif or .php
$copy = copy($_FILES['imagefile']['tmp_name'], "$idir" . $_FILES['imagefile']['name']); // Move Image From Temporary Location To Permanent Location
$bigimg = "$idir" . $_FILES['imagefile']['name'];
$_SESSION["bigimg"] = $bigimg;
$smallimg = "$tdir" . $_FILES['imagefile']['name'];
if ($copy)
{ // If The Script Was Able To Copy The Image To It's Permanent Location
//print 'Imagem enviada com sucesso. -> '; // Was Able To Successfully Upload Image~
//////////////***************************\\\\\\\\\\\\\\\\\\\\\\\\\\\
//envia imagem grand pra bd
$tab = TAB;
$id = $_SESSION["addfoto"];
query("UPDATE `$tab` SET `bimg`='$bigimg' WHERE `id`='$id'");
//////////////***************************\\\\\\\\\\\\\\\\\\\\\\\\\\\
print $bigimg.'<br />';
$simg = imagecreatefromjpeg("$idir" . $url); // Make A New Temporary Image To Create The Thumbanil From
$currwidth = imagesx($simg); // Current Image Width
$currheight = imagesy($simg); // Current Image Height
if ($currheight > $currwidth)
{ // If Height Is Greater Than Width
$zoom = $twidth / $currheight; // Length Ratio For Width
$newheight = $theight; // Height Is Equal To Max Height
$newwidth = $currwidth * $zoom; // Creates The New Width
}
else
{ // Otherwise, Assume Width Is Greater Than Height (Will Produce Same Result If Width Is Equal To Height)
$zoom = $twidth / $currwidth; // Length Ratio For Height
$newwidth = $twidth; // Width Is Equal To Max Width
$newheight = $currheight * $zoom; // Creates The New Height
}
$dimg = imagecreate($newwidth, $newheight); // Make New Image For Thumbnail
imagetruecolortopalette($simg, false, 256); // Create New Color Pallete
$palsize = ImageColorsTotal($simg);
for ($i = 0; $i < $palsize; $i++)
{ // Counting Colors In The Image
$colors = ImageColorsForIndex($simg, $i); // Number Of Colors Used
ImageColorAllocate($dimg, $colors['red'], $colors['green'], $colors['blue']); // Tell The Server What Colors This Image Will Use
}
imagecopyresized($dimg, $simg, 0, 0, 0, 0, $newwidth, $newheight, $currwidth, $currheight); // Copy Resized Image To The New Image (So We Can Save It)
imagejpeg($dimg, "$tdir" . $url); // Saving The Image
$vamos = imagejpeg($dimg, "$tdir" . $url);
imagedestroy($simg); // Destroying The Temporary Image
imagedestroy($dimg); // Destroying The Other Temporary Image
print 'Imagem reduzida enviada com sucesso. -> '; // Resize successful
//////////////***************************\\\\\\\\\\\\\\\\\\\\\\\\\\\
print $smallimg.'<br />';
//envia pequena pra bd
$tab = TAB;
$id = $_SESSION["addfoto"];
query("UPDATE `$tab` SET `simg`='$smallimg' WHERE `id`='$id'");
//////////////***************************\\\\\\\\\\\\\\\\\\\\\\\\\\\
// header("Location: "."?".$_SESSION["string"]."&div=3");
$bas = "index.php?".$_SESSION["string"]."&order=DESC&by=criado&div=4";
echo "<script language=\"JavaScript\">window.location='$bas';</script>";
}
else
{
print '<font color="#FF0000">ERRO: não foi possivel enviar a imagem.</font>';
// header("Location: "."?".$_SESSION["string"]."&div=5"); // Error Message If Upload Failed
$bas = "index.php?".$_SESSION["string"]."&div=5";
echo "<script language=\"JavaScript\">window.location='$bas';</script>";
}
}
else
{
print '<font color="#FF0000">ERRO: Extencao Invalida (Deve ser .jpg ou .jpeg. A sua e '.$file_ext; // Error Message If Filetype Is Wrong
// header("Location: "."?".$_SESSION["string"]."&div=7");
$bas = "index.php"."?".$_SESSION["string"]."&div=7";
echo "<script language=\"JavaScript\">window.location='$bas';</script>";
print $file_ext; // Show The Invalid File's Extention
print '.</font>';
}
}
?>
</div>
</div>
</div>
<?php
print_footer();
?>
Pergunta
m3io
boas malta
eu tenho aki um script que faz upload de uma imagem, cria um thumb e mete na base dados,
funciona tudo direitinho, mas agora encontrei um problema que são os caracteres especiais e os espacos do ficheiro
aki encontrei uma funcao que remove os caracteres e os espacos
<?php function retirar_acentos_caracteres_especiais($string) { $palavra = strtr($string, "ŠŒŽšœžŸ¥µÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖØÙÚÛÜÝßàáâãäåæçèéêëìíîïðñòóôõöøùúûüýÿ", "SOZsozYYuAAAAAAACEEEEIIIIDNOOOOOOUUUUYsaaaaaaaceeeeiiiionoooooouuuuyy"); $palavranova = str_replace("_", " ", $palavra); return $palavranova; } #Exemplo de uso echo retirar_acentos_caracteres_especiais("¥µÀÁÂÃÄÅ"); ?>mas já tentei meter em todo o lado do meu script, mas nada funciona, nem o ficheiro nem a entrada na base dados , fica tudo como original já tentei a funcao no $url, tambem no $_FILES['imagefile']['name'] alguém sabe o problema??? aki vai o meu codigo foto.php<?php require_once("data/init.php"); print_header(); print_centro(); if(!empty($_GET["id"])) { $addfoto = $_GET["id"]; $tabela = "addfoto"; $k = 1; $query = mysql_query("SELECT * FROM `$tabela` WHERE `id`='$k'"); $row = mysql_fetch_assoc($query); if($row["id"]) { $k = 1; query("UPDATE `$tabela` SET `addfoto`='$addfoto' WHERE `id`='$k'"); $_SESSION["addfoto"] = $addfoto; } } ?> <div id="primary"> <div id="content"> <spam><center>Escolha a imagem que deseja adicionar a noticia.</center></spam> </div> <!-- upload form --> <div id="content"> <div class="box"> <?php $idir = IDIR; //dir da img $tdir = TDIR; //dir do thumb // Maximum Width For Thumbnail Images $twidth = TWIDTH; // Maximum Width For Thumbnail Images $theight = THEIGHT; // Maximum Height For Thumbnail Images if (!isset($_GET['subpage'])) { // Image Upload Form Below ?> <form method="post" action="foto.php?subpage=upload" enctype="multipart/form-data"> File:<br /> <input type="file" name="imagefile" class="form"> <br /><br /> <input name="submit" type="submit" value="Adicionar" class="form"> <input type="reset" value="Limpar" class="form"> </form> <?php } else if (isset($_GET['subpage']) && $_GET['subpage'] == 'upload') { // Uploading/Resizing Script $url = $_FILES['imagefile']['name']; // Set $url To Equal The Filename For Later Use if ($_FILES['imagefile']['type'] == "image/jpg" || $_FILES['imagefile']['type'] == "image/jpeg" || $_FILES['imagefile']['type'] == "image/pjpeg") { $file_ext = strrchr($_FILES['imagefile']['name'], '.'); // Get The File Extention In The Format Of , For Instance, .jpg, .gif or .php $copy = copy($_FILES['imagefile']['tmp_name'], "$idir" . $_FILES['imagefile']['name']); // Move Image From Temporary Location To Permanent Location $bigimg = "$idir" . $_FILES['imagefile']['name']; $_SESSION["bigimg"] = $bigimg; $smallimg = "$tdir" . $_FILES['imagefile']['name']; if ($copy) { // If The Script Was Able To Copy The Image To It's Permanent Location //print 'Imagem enviada com sucesso. -> '; // Was Able To Successfully Upload Image~ //////////////***************************\\\\\\\\\\\\\\\\\\\\\\\\\\\ //envia imagem grand pra bd $tab = TAB; $id = $_SESSION["addfoto"]; query("UPDATE `$tab` SET `bimg`='$bigimg' WHERE `id`='$id'"); //////////////***************************\\\\\\\\\\\\\\\\\\\\\\\\\\\ print $bigimg.'<br />'; $simg = imagecreatefromjpeg("$idir" . $url); // Make A New Temporary Image To Create The Thumbanil From $currwidth = imagesx($simg); // Current Image Width $currheight = imagesy($simg); // Current Image Height if ($currheight > $currwidth) { // If Height Is Greater Than Width $zoom = $twidth / $currheight; // Length Ratio For Width $newheight = $theight; // Height Is Equal To Max Height $newwidth = $currwidth * $zoom; // Creates The New Width } else { // Otherwise, Assume Width Is Greater Than Height (Will Produce Same Result If Width Is Equal To Height) $zoom = $twidth / $currwidth; // Length Ratio For Height $newwidth = $twidth; // Width Is Equal To Max Width $newheight = $currheight * $zoom; // Creates The New Height } $dimg = imagecreate($newwidth, $newheight); // Make New Image For Thumbnail imagetruecolortopalette($simg, false, 256); // Create New Color Pallete $palsize = ImageColorsTotal($simg); for ($i = 0; $i < $palsize; $i++) { // Counting Colors In The Image $colors = ImageColorsForIndex($simg, $i); // Number Of Colors Used ImageColorAllocate($dimg, $colors['red'], $colors['green'], $colors['blue']); // Tell The Server What Colors This Image Will Use } imagecopyresized($dimg, $simg, 0, 0, 0, 0, $newwidth, $newheight, $currwidth, $currheight); // Copy Resized Image To The New Image (So We Can Save It) imagejpeg($dimg, "$tdir" . $url); // Saving The Image $vamos = imagejpeg($dimg, "$tdir" . $url); imagedestroy($simg); // Destroying The Temporary Image imagedestroy($dimg); // Destroying The Other Temporary Image print 'Imagem reduzida enviada com sucesso. -> '; // Resize successful //////////////***************************\\\\\\\\\\\\\\\\\\\\\\\\\\\ print $smallimg.'<br />'; //envia pequena pra bd $tab = TAB; $id = $_SESSION["addfoto"]; query("UPDATE `$tab` SET `simg`='$smallimg' WHERE `id`='$id'"); //////////////***************************\\\\\\\\\\\\\\\\\\\\\\\\\\\ // header("Location: "."?".$_SESSION["string"]."&div=3"); $bas = "index.php?".$_SESSION["string"]."&order=DESC&by=criado&div=4"; echo "<script language=\"JavaScript\">window.location='$bas';</script>"; } else { print '<font color="#FF0000">ERRO: não foi possivel enviar a imagem.</font>'; // header("Location: "."?".$_SESSION["string"]."&div=5"); // Error Message If Upload Failed $bas = "index.php?".$_SESSION["string"]."&div=5"; echo "<script language=\"JavaScript\">window.location='$bas';</script>"; } } else { print '<font color="#FF0000">ERRO: Extencao Invalida (Deve ser .jpg ou .jpeg. A sua e '.$file_ext; // Error Message If Filetype Is Wrong // header("Location: "."?".$_SESSION["string"]."&div=7"); $bas = "index.php"."?".$_SESSION["string"]."&div=7"; echo "<script language=\"JavaScript\">window.location='$bas';</script>"; print $file_ext; // Show The Invalid File's Extention print '.</font>'; } } ?> </div> </div> </div> <?php print_footer(); ?>va malta alguém me ajude a perceber o problema.
"melhor ensinar a pescar que dar o peixe"
preciso é que me ensinem a pescar
Editado por m3ioLink para o comentário
Compartilhar em outros sites
13 respostass a esta questão
Posts Recomendados
Participe da discussão
Você pode postar agora e se registrar depois. Se você já tem uma conta, acesse agora para postar com sua conta.