Jump to content
Fórum Script Brasil
  • 0

O que pode estar errado neste codigo?


Guest --Janio --

Question

Guest --Janio --

O codigo abaix faz parte de um script pra envio de noticias para um DB, e envia junto uma imagem referente ao artigo, so que no final ele não esta copiando a imagem, se alguém puder me identificar aonte esta o erro agradeço.

if(!empty($HTTP_POST_FILES['filename']['name']))
  {
   $HTTP_POST_FILES['filename']['name'] = eregi_replace(" ","",$HTTP_POST_FILES['filename']['name']);
   $HTTP_POST_FILES['filename']['name'] = eregi_replace("/","",$HTTP_POST_FILES['filename']['name']);
   $HTTP_POST_FILES['filename']['name'] = eregi_replace("@","",$HTTP_POST_FILES['filename']['name']);
   $HTTP_POST_FILES['filename']['name'] = eregi_replace("%","",$HTTP_POST_FILES['filename']['name']);
   $HTTP_POST_FILES['filename']['name'] = eregi_replace("\"","",$HTTP_POST_FILES['filename']['name']);
   $HTTP_POST_FILES['filename']['name'] = eregi_replace("'","",$HTTP_POST_FILES['filename']['name']);
   $HTTP_POST_FILES['filename']['name'] = eregi_replace(",","",$HTTP_POST_FILES['filename']['name']);
   
// Faz conversao do nome da imagem para um nome unico formado por data e hora 
// e checo seu formato antes de renomear para o seu formato correto  
$data = date("dmYGis"); // data usada para renomear os arquivos de imagem

   if($HTTP_POST_FILES['filename']['type'] == "image/jpeg")
      {
        $HTTP_POST_FILES['filename']['name'] = eregi_replace($HTTP_POST_FILES['filename']['name'],"$data.jpg",$HTTP_POST_FILES['filename']['name']);
      }
   if($HTTP_POST_FILES['filename']['type'] == "image/pjpeg")
      {
        $HTTP_POST_FILES['filename']['name'] = eregi_replace($HTTP_POST_FILES['filename']['name'],"$data.jpg",$HTTP_POST_FILES['filename']['name']);
      }    

   if($HTTP_POST_FILES['filename']['type'] == "image/gif")
      {
        $HTTP_POST_FILES['filename']['name'] = eregi_replace($HTTP_POST_FILES['filename']['name'],"$data.gif",$HTTP_POST_FILES['filename']['name']);
      }
   if($HTTP_POST_FILES['filename']['type'] == "image/x-png")
      {
        $HTTP_POST_FILES['filename']['name'] = eregi_replace($HTTP_POST_FILES['filename']['name'],"$data.png",$HTTP_POST_FILES['filename']['name']);
      }   
 // final de renomear 
   //echo $HTTP_POST_FILES['filename']['tmp_name'],$GLOBALS['news_path']."/".$HTTP_POST_FILES['filename']['name'];
   if($HTTP_POST_FILES['filename']['type'] == "image/jpeg" | $HTTP_POST_FILES['filename']['type'] == "image/pjpeg" | $HTTP_POST_FILES['filename']['type'] == "image/gif" | $HTTP_POST_FILES['filename']['type'] == "image/x-png") 
   {
    if(file_exists($GLOBALS['news_path']."/".$HTTP_POST_FILES['filename']['name'])) 
      echo "&lt;script type=\"text/javascript\">alert('"._FILEALREADYEXIST."');</script>";
    else
     if(!move_uploaded_file($HTTP_POST_FILES['filename']['tmp_name'],$GLOBALS['news_path']."/".$HTTP_POST_FILES['filename']['name']))
       echo "&lt;script type=\"text/javascript\">alert('"._ERROR."');</script>";
     else 
     {
      chmod($GLOBALS['news_path']."/".$HTTP_POST_FILES['filename']['name'],0644);
        echo "&lt;script type=\"text/javascript\">alert('"._SUCCESS."');</script>";
     }
    }
    else 
     echo _WRONGDATATYPE.": ".$HTTP_POST_FILES['filename']['type']."<br />";

Ele não esta copiando a imagem para a pasta de destino no servidor, a mesma contem todas permicoes de gravacao tipo 777.

alguém pode me ajudar?

Link to comment
Share on other sites

3 answers to this question

Recommended Posts

  • 0
Guest --Janio --

function EditNews()
{
 if(!check_version("4.1.0")) global $_GET,$_POST;
 global $HTTP_POST_FILES;

 if(CheckPriv("news_edit") == 0)
 {
  ShowMain();
  echo "<script type=\"text/javascript\">alert('"._NOTENOUGHPRIV."');</script>";
  return;
 }

 $res = mysql_query("SELECT * from ".$GLOBALS['db_destaques']." WHERE id='".$_GET['id']."'") or die("<b>Line 292:</b>".mysql_error());
 $ar = mysql_fetch_array($res);
 if(CheckPriv("news_mod") == 0 && $ar[author] <> $GLOBALS['login'])
 {
  ShowMain();
  echo "<script type=\"text/javascript\">alert('"._NOTYOURNEWS."');</script>";
  return;
 }

 if ($_POST['confirm'] == "picture") 
 {
  if(!empty($HTTP_POST_FILES['filename']['name']))
  {
   $HTTP_POST_FILES['filename']['name'] = eregi_replace(" ","",$HTTP_POST_FILES['filename']['name']);
   $HTTP_POST_FILES['filename']['name'] = eregi_replace("/","",$HTTP_POST_FILES['filename']['name']);
   $HTTP_POST_FILES['filename']['name'] = eregi_replace("@","",$HTTP_POST_FILES['filename']['name']);
   $HTTP_POST_FILES['filename']['name'] = eregi_replace("%","",$HTTP_POST_FILES['filename']['name']);
   $HTTP_POST_FILES['filename']['name'] = eregi_replace("\"","",$HTTP_POST_FILES['filename']['name']);
   $HTTP_POST_FILES['filename']['name'] = eregi_replace("'","",$HTTP_POST_FILES['filename']['name']);
   $HTTP_POST_FILES['filename']['name'] = eregi_replace(",","",$HTTP_POST_FILES['filename']['name']);
   
// Faz conversao do nome da imagem para um nome unico formado por data e hora 
// e checo seu formato antes de renomear para o seu formato correto  
$data = date("dmYGis"); // data usada para renomear os arquivos de imagem

   if($HTTP_POST_FILES['filename']['type'] == "image/jpeg")
      {
        $HTTP_POST_FILES['filename']['name'] = eregi_replace($HTTP_POST_FILES['filename']['name'],"$data.jpg",$HTTP_POST_FILES['filename']['name']);
      }
   if($HTTP_POST_FILES['filename']['type'] == "image/pjpeg")
      {
        $HTTP_POST_FILES['filename']['name'] = eregi_replace($HTTP_POST_FILES['filename']['name'],"$data.jpg",$HTTP_POST_FILES['filename']['name']);
      }    

   if($HTTP_POST_FILES['filename']['type'] == "image/gif")
      {
        $HTTP_POST_FILES['filename']['name'] = eregi_replace($HTTP_POST_FILES['filename']['name'],"$data.gif",$HTTP_POST_FILES['filename']['name']);
      }
   if($HTTP_POST_FILES['filename']['type'] == "image/x-png")
      {
        $HTTP_POST_FILES['filename']['name'] = eregi_replace($HTTP_POST_FILES['filename']['name'],"$data.png",$HTTP_POST_FILES['filename']['name']);
      }   
 // final de renomear 
   //echo $HTTP_POST_FILES['filename']['tmp_name'],$GLOBALS['destaques_path']."/".$HTTP_POST_FILES['filename']['name'];
   if($HTTP_POST_FILES['filename']['type'] == "image/jpeg" | $HTTP_POST_FILES['filename']['type'] == "image/pjpeg" | $HTTP_POST_FILES['filename']['type'] == "image/gif" | $HTTP_POST_FILES['filename']['type'] == "image/x-png") 
   {
    if(file_exists($GLOBALS['destaques_path']."/".$HTTP_POST_FILES['filename']['name'])) 
      echo "<script type=\"text/javascript\">alert('"._FILEALREADYEXIST."');</script>";
    else
     if(!move_uploaded_file($HTTP_POST_FILES['filename']['tmp_name'],$GLOBALS['destaques_path']."/".$HTTP_POST_FILES['filename']['name']))
       echo "<script type=\"text/javascript\">alert('"._ERROR."');</script>";
     else 
     {
      chmod($GLOBALS['destaques_path']."/".$HTTP_POST_FILES['filename']['name'],0644);
        echo "<script type=\"text/javascript\">alert('"._SUCCESS."');</script>";
     }
    }
    else 
     echo _WRONGDATATYPE.": ".$HTTP_POST_FILES['filename']['type']."<br />";
    $resx = mysql_query("SELECT imagem FROM ".$GLOBALS['db_destaques']." WHERE id='".$_POST['id']."'") or die("<b>Error 228:</b>".mysql_error());
    $arx  = mysql_fetch_array($resx);
    //if(file_exists($GLOBALS['destaques_path']."/".$arx[picture])) unlink ($GLOBALS['destaques_path']."/".$arx[picture]);
    mysql_query("UPDATE ".$GLOBALS['db_destaques']." SET imagem='".$HTTP_POST_FILES['filename']['name']."' WHERE id='".$_POST['id']."'") or die("<b>Error 233:</b>".mysql_error());
   }
 } 
 if($_POST['confirm'] == "true") 
 {
  //echo ConvertHTML($_POST['message']);
   mysql_query("UPDATE ".$GLOBALS['db_destaques']." SET titulo='".$_POST['titulo']."', descricao='".ConvertHTML($_POST['descricao'])."', area='".$_POST['area']."', noticia_id='".ConvertHTML($_POST['noticia_id'])."', categoria_id ='".ConvertHTML($_POST['categoria_id'])."', datum2='CURRENT_TIMESTAMP' WHERE id='".$_POST['id']."'") or die("<b>Error 81:</b>".mysql_error());
   makeRSS();
   ShowMain();
  } 
  else
  {
   $res = mysql_query("SELECT * from ".$GLOBALS['db_destaques']." WHERE id='".$_GET['id']."'") or die("<b>Line 292:</b>".mysql_error());
   $ar = mysql_fetch_array($res);

   $ar[headline] = ereg_replace( "&quot;","'",$ar[headline]);
   $ar[headline] = ereg_replace( "&acute;","'",$ar[headline]);
   $ar[legend] = ereg_replace( "&acute;","'",$ar[legend]);
   ?>
   <table width="630" cellspacing="2" cellpadding="0" class="MojText">
    <tr>
     <td width="20"><a href="<?=$GLOBALS['PHP_SELF'];?>"><img src="gfx/news_big.jpg" width="32" height="32" border="0" alt="<?=_ADDNEWS;?>"/></a></td>
   <td width="100"><a href="<?=$GLOBALS['PHP_SELF'];?>"><?=_MAINMENU;?></a></td>
   <td align="center"><font size="4" face="Arial"> <b><?=_EDITNEWS;?></b></font></td>
   <td align="right">
    <?
    $res = mysql_query("SELECT * FROM ".$GLOBALS['db_destaques']) or die("<b>Line 246:</b>".mysql_error());
    echo _SUBMITEDNEWS.": ".mysql_num_rows($res);
    ?>
   </td>
  </tr>
 </table>

 <table width="630" cellspacing="2" cellpadding="1" class="MojText">
  <tr bgcolor="#<?=_COLOR02;?>">
   <td>&nbsp;</td>
  </tr>
 </table>

  <a name="addit"></a>
  <form action="<?=$GLOBALS['PHP_SELF'];?>" method="post" name="novica"> 
   <table width="100%" border="0" cellspacing="0" cellpadding="0" align="center" class="MojText">
   <tr> 
    <td valign="top" width="70%">
    <?=_NEWSHEADLINE;?><br />
     <input type="text" name="titulo" value="<?echo $ar[titulo];?>" class="news" size="60" /><br />
     <br/>
    <?=_NEWSID;?><br />
     <input type="text" name="noticia_id" value="<?echo $ar[noticia_id];?>" class="news" size="10" /><br />
     <br/>
    <?=_CATEGORYID;?><br />
     <input type="text" name="categoria_id" value="<?echo $ar[categoria_id];?>" class="news" size="10" /><br />
     <br/>
     <?=_AREA;?>:<br />
     <select name="area" class="news">
    <?
       $res3 = mysql_query("SELECT * FROM ".$GLOBALS['db_area']) or die("<b>Error 271:</b>".mysql_error());
       while ($ar3= mysql_fetch_array($res3))
      {
       echo "<option value=\"$ar3[0]\" ";
       if($ar3[area_id] == $ar[area]) 
         echo " selected=\"selected\" ";
       echo ">$ar3[nome]</option>";
      }

      ?>      </select><br />

     <table width="440"><tr><td><?=_RESUMO;?></td><td align="right">
      <input type="button" accesskey="B" value="B" class="news" onclick="insert_tag('B','preview')" title="BOLD: [Control / Alt] + b" style="width:25px;font-weight:bold" />
      <input type="button" accesskey="B" value="/B" class="news" onclick="insert_tag('/B','preview');" title="BOLD: [Control / Alt] + SHIFT + B" style="width:25px;font-weight:bold" />
      <input type="button" accesskey="i" value="I" class="news" onclick="insert_tag('I','preview');" title="ITALIC: [Control / Alt] + i" style="width:25px;font-style:italic" />
      <input type="button" accesskey="I" value="/I" class="news" onclick="insert_tag('/I','preview');" title="ITALIC: [Control / Alt] + SHIFT + I" style="width:25px;font-style:italic" />
      <input type="button" accesskey="u" value="U" class="news" onclick="insert_tag('U','preview');" title="UNDERLINE: [Control / Alt] + u" style="width:25px;text-decoration:underline" />
      <input type="button" accesskey="U" value="/U" class="news" onclick="insert_tag('/U','preview');" title="UNDERLINE: [Control / Alt] + SHIFT + U" style="width:25px;text-decoration:underline" />
     </td></tr></table>
     <textarea onchange="MakePreview" onkeydown="MakePreview()" onblur="MakePreview" onkeyup="MakePreview()" name="descricao" class="news" rows="" cols="" style="width:98%;height:100px;"><?=UnConvertHTML($ar['descricao']);?></textarea><br/>
     <!-- final area de edicao -->

    </td>
   </tr>
   <tr>
    <td colspan="2" width="30%">
     <br/>
     <input type="hidden" name="id" value="<?=$_GET['id'];?>" />
     <input type="hidden" name="confirm" value="true" />
     <input type="hidden" name="action" value="edit" />
     <br/>
     <input type="submit" value="<?=_SUBMIT;?>" style="width:114px;height:35px;background-image: url(./gfx/button.gif);" />
     <br/>
     <input type="checkbox" name="makreprev" onclick="ResetPreview();MakePreview();" value="1"><?=_PREVIEW_NEWS;?><br/>
     <input type="checkbox" name="newwindow" value="1"><?=_OPEN_NEW_WINDOW;?><br/>
    </td>
   </tr>
  </table>
  </form>
  <table width="100%" border="0" cellspacing="0" cellpadding="0" align="center" class="Mojtext">
   <tr>
   <td>
        <br />
        <?
         if(file_exists($GLOBALS['destaques_path']."/".$ar[imagem]) && !empty($ar[imagem])) 
         {
          $size = getimagesize($GLOBALS['destaques_path']."/".$ar[imagem]);
          echo '<img src="'.$GLOBALS['destaques_path']."/".$ar[imagem].'" alt="" ';
          if($size[0]>600) echo 'width="600"';
          echo '/>';
         }
        ?>
        <br />

        <form action="<?=$GLOBALS['PHP_SELF'];?>" enctype="multipart/form-data" method="post"> 
        <?=_UPLOADPICTURE;?>:<br />
        <input type="file" class="news" name="filename" size="50" /><br />
        <input type="hidden" name="action" value="edit" /><br /><br />
        <input type="hidden" name="confirm" value="picture" />
        <input type="hidden" name="id" value="<?=$_GET['id'];?>" />

        <input type="submit" value="<?=_SUBMIT;?>" style="width:114px;height:35px;background-image: url(./gfx/button.gif);" />
         </form>
     </td>
   </tr>
  </table>
  <hr/>
  <p id="tiph" tyle="width:620px; text-align:justify; overflow:auto; height:400px;"></p>
  <p id="tipp" tyle="width:620px; text-align:justify; overflow:auto; height:400px;"></p>
  <p id="tipm" tyle="width:620px; text-align:justify; overflow:auto; height:400px;"></p>
  <?
 }
}

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Answer this question...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.



  • Forum Statistics

    • Total Topics
      152k
    • Total Posts
      651.5k
×
×
  • Create New...