Jump to content


Photo

Problema Com "Move-Uploaded-File"


  • Faça o login para participar
4 replies to this topic

#1 angelomaia

angelomaia

    Novato no fórum

  • Usuários
  • 4 posts
  • Sexo:Masculino
  • Localidade:RJ

Posted 06/05/2011, 01:34

Pessoal, sou novo ainda em php, estou estudando e para isso como tarefa peguei um script de um classificado, dei umas melhoradas e até está legal, porém está gerando um erro ao enviar uma foto, utilizando o comando move-uploaded-file, como segue abaixo:

Warning: move_uploaded_file(/public_html/imagens/anunciantes/216852g.jpg) [function.move-uploaded-file]: failed to open stream: No such file or directory in /home/wwwclass/public_html/adm3306/cadastro.php on line 54

Warning: move_uploaded_file() [function.move-uploaded-file]: Unable to move '/tmp/phpFTacO7' to '/public_html/imagens/anunciantes/216852g.jpg' in /home/wwwclass/public_html/adm3306/cadastro.php on line 54
Duplicate entry '0' for key 1

Se possível, agradeço as dicas dos amigos.

Angelo

#2 Diego Bezerra

Diego Bezerra

    Diego Bezerra

  • Moderadores
  • 938 posts
  • Sexo:Masculino
  • Localidade:Amazonas
  • Interesses:Iniciando no C# com MSSQL.

Posted 06/05/2011, 08:33

tem como vc colocar o codigo do arquivo PHP
Att.
Diego Bezerra
Agência Kernel - em Breve
Email/msn: diegobezerra@outlook.com
Facebook

#3 angelomaia

angelomaia

    Novato no fórum

  • Usuários
  • 4 posts
  • Sexo:Masculino
  • Localidade:RJ

Posted 06/05/2011, 10:17

O erro acontece, quando na área administrativa eu tento cadastrar um novo anúncio. O anúncio é cadastrado, mas a imagem não aparece. Segue abaixo, o código do arquivo cadastro.php

<?
require("AreaRestrita.php");
include("../includes/config.php");
?>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Cadastro</title>

<style type="text/css">
<!--
.style1 { font-family: Verdana, Arial, Helvetica, sans-serif;
color: #FFFFFF;
}
.style3 { color: #FFFFFF;
font-family: "Courier New", Courier, monospace;
font-weight: bold;
}
-->
</style>
</head>

<body>
<?

$data = date("d/m/Y");


################################
function initRand ()
{
static $randCalled = FALSE;
if (!$randCalled)
{
srand((double) microtime() * 1000000);
$randCalled = TRUE;
}
}
function randNum ($low, $high)
{
initRand();
$rNum = rand($low, $high);
return $rNum;
}
// setando o mínimo é o máximo que o número aleatório deve chegar
$num_imagem = randNum(0101,999999);

if($anunciante != ""){
if($file != ""){

$f_name = $_FILES['file']['name'];
$ext = substr($f_name,-5);
$dir = $DirRoot."imagens/anunciantes";
$status = move_uploaded_file($file,"$dir"."/"."$num_imagem"."$ext");

$cadastra = mysql_query("INSERT INTO anunciantes
(id_categoria,
anunciante,
endereco,
telefone,
email,
site,
descricao,
imagem,
exibe,
dt_cadastro)
VALUES
('$categoria',
'$anunciante',
'$endereco',
'$telefone',
'$email',
'$site',
'$descricao',
'$num_imagem$ext',
'$exibe',
'$data')");
}else{
$cadastra = mysql_query("INSERT INTO anunciantes
(id_categoria,
anunciante,
endereco,
telefone,
email,
site,
descricao,
exibe,
dt_cadastro)
VALUES
('$categoria',
'$anunciante',
'$endereco',
'$telefone',
'$email',
'$site',
'$descricao',
'$exibe',
'$data')");
}
if($cadastra){
echo "<script>javascript:alert('Cacastrado com sucesso.');</script>";
}else{
echo mysql_error();
}
}

?>
<table align="center" width="450" border="0" cellspacing="0" cellpadding="0">
<tr><br />
<br />
<br />
<td bgcolor="#0178B3"><div align="center" class="style1 style3">Cadastro de Anunciante</div></td>
</tr>
</table>
<form id="form1" name="form1" method="post" action="" enctype="multipart/form-data">
<label></label>
<label>

</label>
<table width="345" border="0" align="center" cellpadding="0" cellspacing="0">
<tr>
<td><font size="1" face="Verdana, Arial, Helvetica, sans-serif">Categoria:</font> </td>
<td><select name="categoria" id="categoria">
<?php combo_jornais ( -1 ); ?>
</select></td>
</tr>
<tr>
<td width="96"><font size="1" face="Verdana, Arial, Helvetica, sans-serif">Anunciante:</font> </td>
<td width="249"><input name="anunciante" type="text" id="anunciante" size="40" /></td>
</tr>
<tr>
<td><font size="1" face="Verdana, Arial, Helvetica, sans-serif">Endere&ccedil;o:</font> </td>
<td><input name="endereco" type="text" id="endereco" size="40" /></td>
</tr>
<tr>
<td><font size="1" face="Verdana, Arial, Helvetica, sans-serif">Telefone:</font></td>
<td><input name="telefone" type="text" id="telefone" size="40" /></td>
</tr>
<tr>
<td><font size="1" face="Verdana, Arial, Helvetica, sans-serif">E-mail:</font></td>
<td><input name="email" type="text" id="email" size="40" /></td>
</tr>
<tr>
<td><font size="1" face="Verdana, Arial, Helvetica, sans-serif">Site:</font></td>
<td><input name="site" type="text" id="site" size="40" /></td>
</tr>
<tr>
<td><font size="1" face="Verdana, Arial, Helvetica, sans-serif">Descri&ccedil;&atilde;o:</font></td>
<td><textarea name="descricao" cols="40" rows="5" id="descricao"></textarea></td>
</tr>
<tr>
<td><font size="1" face="Verdana, Arial, Helvetica, sans-serif">Imagem:</font></td>
<td><input name="file" type="file" class="campoform"></td>
</tr>
<tr>
<td><font size="1" face="Verdana, Arial, Helvetica, sans-serif">Exibir?:</font></td>
<td><label>
<input name="exibe" type="radio" id="radio" value="1" checked>
</label>
<font size="1" face="Verdana, Arial, Helvetica, sans-serif">Sim</font>
<label>
<input name="exibe" type="radio" id="radio2" value="0">
</label>
<font size="1" face="Verdana, Arial, Helvetica, sans-serif">N&atilde;o</font></td>
</tr>
<tr>
<td>&nbsp;</td>
<td><input type="submit" name="Submit" value="Cadastrar" /></td>
</tr>
</table>
</form>
</body>
</html>
<?
// jornais

function combo_jornais ( $id_categorias )

{

global $Connection;

$sSql = " SELECT * ";
$sSql .= " FROM categorias";
$sSql .= " ORDER BY id ";

$Result = mysql_query( $sSql );

if ( !$Result )
exit( " Erro : ao Procurar Dados das categorias = > " . mysql_error());

while( $aResult = mysql_fetch_array( $Result ) )

{

if ( $id_categorias == $aResult["id"] )
print "<option value=\"" . $aResult["id"] . "\" selected >" . $aResult["categoria"] . "</option>\n";
else
print "<option value=\"" . $aResult["id"] . "\" >" . $aResult["categoria"] . "</option>\n";

}

}
?>



#4 Diego Bezerra

Diego Bezerra

    Diego Bezerra

  • Moderadores
  • 938 posts
  • Sexo:Masculino
  • Localidade:Amazonas
  • Interesses:Iniciando no C# com MSSQL.

Posted 06/05/2011, 11:04

tenta subistituir a parde de upload por esta


f($anunciante != ""){
if($file != ""){

$f_name = $_FILES['file']['name'];
$ext = substr($f_name,-5);
$dir = $DirRoot."imagens/anunciantes";
$status = move_uploaded_file($file,"$dir"."/"."$num_imagem"." $ext");

<?php
    $file = $_FILES['file']['name'];
    $file_size = $_FILES['file']['size'];
    $file_temp = $_FILES['file']['tmp_name'];
    $file_err = $_FILES['file']['error'];
    $path = 'imagens/anunciantes/';
    $randomizer = rand(0000, 9999);
    $file_name = $randomizer.$userfile;
    $file_type = $file;
    $file_type_length = strlen($file_type) - 3;
    $file_type = substr($file_type, $file_type_length);
    if(!empty($file)) {
        echo '<div style="font-weight: bold; padding: 6px;">File Uploaded  Information</div>
        <ul>
        <li>Nome riginal: ' .$userfile. '</li>
        <li>Novo nome: ' .$file_name. '</li>
        <li>Tipe: ' .$file_type.'</li>
        <li>tamanho: ' .$file_size. '</li>
        <li>nome temporario: ' .$file_temp. '</li>
        <li>Erro: ' . $file_err. '</li>
        </ul>';

        // limite 200KB
        if($file_size > 25600) {
            echo 'FILE SIZE TO LARGE - ASSIMA DO TAMANHO PERMITIDO<BR />';
            exit();
        }

        $file_type = strtolower($file_type);
        $files = array();
        $files[] = 'jpeg';
        $files[] = 'jpg';
        $files[] = 'gif';
        $files[] = 'png';

        $key = array_search($file_type, $files);
        if($key) {
            echo '<b>Arquivo ok!</b><br />';
        } else {
            echo '<b>Tipo não permitido</b><br />';
            exit();
        }

$error_count = count($file_error);
if($error_count > 0) {
        for($i = 0; $i <= $error_count; ++$i) {
            echo $_FILES['file']['error'][$i];
        }
} else {
        if(move_uploaded_file($file_temp, 'imagens/anunciantes/' .$file_name.'')) {
            echo '<h3>Upload feito com susseso!</h3>';
        } else {
            echo '<h3>ERROR</h3>';
        }
}

    } else {
        echo '<h3>Você não selecionou um arquivo.</h3>';
    }
?>

Att.
Diego Bezerra
Agência Kernel - em Breve
Email/msn: diegobezerra@outlook.com
Facebook

#5 angelomaia

angelomaia

    Novato no fórum

  • Usuários
  • 4 posts
  • Sexo:Masculino
  • Localidade:RJ

Posted 08/05/2011, 10:02

Diego, agora o código do arquivo cadastra.php ficou assim, segundo sua orientação:

<?php
require("AreaRestrita.php");
include("../includes/config.php");
?>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Cadastro</title>

<style type="text/css">
<!--
.style1 { font-family: Verdana, Arial, Helvetica, sans-serif;
color: #FFFFFF;
}
.style3 { color: #FFFFFF;
font-family: "Courier New", Courier, monospace;
font-weight: bold;
}
-->
</style>
</head>

<body>
<?php

$data = date("d/m/Y");


################################
function initRand ()
{
static $randCalled = FALSE;
if (!$randCalled)
{
srand((double) microtime() * 1000000);
$randCalled = TRUE;
}
}
function randNum ($low, $high)
{
initRand();
$rNum = rand($low, $high);
return $rNum;
}
// setando o mínimo é o máximo que o número aleatório deve chegar
$num_imagem = randNum(0101,999999);

if($anunciante != ""){
if($file != ""){

$f_name = $_FILES['file']['name'];
$ext = substr($f_name,-5);
$dir = $DirRoot."imagens/anunciantes";
$status = move_uploaded_file($file,"$dir"."/"."$num_imagem"."
$ext");

?>

<?php
$file = $_FILES['file']['name'];
$file_size = $_FILES['file']['size'];
$file_temp = $_FILES['file']['tmp_name'];
$file_err = $_FILES['file']['error'];
$path = 'imagens/anunciantes/';
$randomizer = rand(0000, 9999);
$file_name = $randomizer.$userfile;
$file_type = $file;
$file_type_length = strlen($file_type) - 3;
$file_type = substr($file_type, $file_type_length);
if(!empty($file)) {
echo '<div style="font-weight: bold; padding: 6px;">File Uploaded Information</div>
<ul>
<li>Nome riginal: ' .$userfile. '</li>
<li>Novo nome: ' .$file_name. '</li>
<li>Tipe: ' .$file_type.'</li>
<li>tamanho: ' .$file_size. '</li>
<li>nome temporario: ' .$file_temp. '</li>
<li>Erro: ' . $file_err. '</li>
</ul>';

// limite 200KB
if($file_size > 25600) {
echo 'FILE SIZE TO LARGE - ASSIMA DO TAMANHO PERMITIDO<BR />';
exit();
}

$file_type = strtolower($file_type);
$files = array();
$files[] = 'jpeg';
$files[] = 'jpg';
$files[] = 'gif';
$files[] = 'png';

$key = array_search($file_type, $files);
if($key) {
echo '<b>Arquivo ok!</b><br />';
} else {
echo '<b>Tipo não permitido</b><br />';
exit();
}

$error_count = count($file_error);
if($error_count > 0) {
for($i = 0; $i <= $error_count; ++$i) {
echo $_FILES['file']['error'][$i];
}
} else {
if(move_uploaded_file($file_temp, 'imagens/anunciantes/' .$file_name.'')) {
echo '<h3>Upload feito com susseso!</h3>';
} else {
echo '<h3>ERROR</h3>';
}
}

} else {
echo '<h3>Você não selecionou um arquivo.</h3>';
}
?>


Porém está dando o erro...

Parse error: syntax error, unexpected $end in /home/wwwclass/public_html/adm3306/cadastro.php on line 118


Dei uma verificada e não consegui concertar. Obrigado pela força. Se puder me ajudar, te agradeço.

Algum desenvolvedor tiver disponibilidade, podemos ver um valor pra arrumar essa função do move-uploaded-file. Obrigado.

Algum desenvolvedor tiver disponibilidade, podemos ver um valor pra arrumar essa função do move-uploaded-file. Obrigado.




1 user(s) are reading this topic

0 membro(s), 1 visitante(s) e 0 membros anônimo(s)

IPB Skin By Virteq