2013-10-15 55 views
0

我住在巴西,發現這個網站提出問題。發現它非常好。- move_uploaded_file

「m該錯誤消息

Warning: move_uploaded_file(): The second argument to copy() function cannot be a directory in C:\wamp\www\imoveis\cadastro.php on line 22 
Call Stack 


Warning: move_uploaded_file(): Unable to move 'C:\wamp\tmp\php6DC1.tmp' to 'banners/' in C:\wamp\www\imoveis\cadastro.php on line 22 

這是代碼行是給予麻煩;

if(move_uploaded_file($banner_tmp, "banners/".$banner)): 

本頁面cadastro.php

<?php 
    include_once "conexao/config.php"; 
    include_once "functions/functions.php"; 


    if(isset($_POST['cadastrar'])): 
     $titulo = filter_input(INPUT_POST, 'titulo', FILTER_SANITIZE_STRING); 
     $descricao = filter_input(INPUT_POST, 'descricao', FILTER_SANITIZE_STRING); 
     $banner_tmp = $_FILES['banner']['tmp_name']; 

     $larguraPermitida = 900; 
     $alturaPermitida = 300; 
     $dadosFoto = getimagesize($banner_tmp); 
     list($largura, $altura ,$numero, $tipo)= $dadosFoto; 

      if($largura > $larguraPermitida): 
         echo "Largura não pode ser maior que ".$larguraPermitida; 
          elseif($altura > $alturaPermitida): 
           echo "Altura não pode ser maior que ".$alturaPermitida; 
          else: 
       if(move_uploaded_file($banner_tmp, "banners/".$banner)): 
         cadastrarBanners($titulo,$banner,$descricao); 
         else: 
          echo "erro ao fazer upload"; 
       endif; 
      endif; 
     endif; 



?> 



<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 
<html xmlns="http://www.w3.org/1999/xhtml"> 
<head> 

<link rel="stylesheet" href="estilo/estilo.css" type="text/css" /> 

<link rel="stylesheet" href="estilo/acadastrar_admin.css" type="text/css"> 
<link rel="stylesheet" href="estilo/estilo.css" type="text/css" /> 
<link rel="stylesheet" href="estilo/button_iniciar.css" type="text/css"> 
<link rel="stylesheet" href="estilo/button_sobre.css" type="text/css"> 
<link rel="stylesheet" href="estilo/button_investir.css" type="text/css"> 
<link rel="stylesheet" href="estilo/button_imoveis.css" type="text/css"> 
<link rel="stylesheet" href="estilo/coin-slider-styles.css" type="text/css"> 

<meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> 
<title>Cadastrar Banners</title> 
</head> 

<body> 
<table width="1348" align="center" cellspacing="0" cellpadding="0"> 
    <tr> 
    <th scope="col"> 
      <div id="topo"> 
      <div id="telefone"> 
       055 81 9992-5152 
      </div> 
     </div> 
    </th> 
    </tr> 
    <tr> 
    <td><?php include_once('menu.php');?></td> 
    </tr> 
    <tr> 
    <td> <div id="conteudo"> 
     <?php include_once('menu.php');?> 
     <div id="cadastrar_administrador"> 

     <form action="" method="post" enctype="multipart/form-data"> 
     <fieldset class="first"> 
      <label class="labelOne" for="titulo">Titulo:</label>    
      <input type="text" name="titulo"/> 

      <label for="descricao">Descrição:</label> 
      <input type="text" name="descricao"/> 

      <label for="banner">Banner:</label> 
      <input type="file" name="banner"/> 

      <label class="btn" for="submit"></label> 
      <input class="btn" type="submit" name="cadastrar" value="Cadastrar Banner"/> 
     </fieldset> 
     </form> 

    </div> 

    </div> 

    </td> 
    </tr> 
    <tr> 
    <td><div align="center" id="rodape"> 
sjncsjknckjsdc 
    </div> 
</td> 
    </tr> 
</table> 
</body> 
</html> 

有人可以幫我請。

+1

您有試過絕對路徑?即'C:\ wamp \ htdocs \ ... \ banners' - 這個目錄是否也存在?並有寫權限? – SmokeyPHP

+0

它的窗口,所以寫入權限可能不是問題。絕對需要使用絕對路徑。 –

+1

'「banners /".$ banner' - 你的代碼中定義了'$ banner'的位置嗎? – CBroe

回答

1

這是造成問題的行:

if(move_uploaded_file($banner_tmp, "banners/".$banner)): 

你應該通過像這樣的絕對路徑:

if(move_uploaded_file($banner_tmp, dirname(__FILE__) . "/banners/".$banner)): 

if(move_uploaded_file($banner_tmp, "C:/some/folder/banners/".$banner)): 
+0

爲什麼downvote OP? –

0

橫幅/是錯誤的

你應該寫這樣 如果(move_uploaded_file($ banner_tmp, 「/條幅/ $旗幟」)):

簡單的例子。只有對於演示...

<?php 
    $uploads_dir = '/uploads'; 

    foreach ($_FILES["pictures"]["error"] as $key => $error) 
    { 
      if ($error == UPLOAD_ERR_OK) 
      { 
       $tmp_name = $_FILES["pictures"]["tmp_name"][$key]; 
       $name = $_FILES["pictures"]["name"][$key]; 
       move_uploaded_file($tmp_name, "$uploads_dir/$name"); 
      } 
     } 
    ?> 


    /*Try this working code for move_uploaded_files */ 

    <?php 

      if(isset($_FILES['uploaded'])){ 
      $target = "galleries/".basename($_FILES['uploaded']['name']) ; 
      print_r($_FILES); 

      if(move_uploaded_file($_FILES['uploaded']['tmp_name'],$target)) 
        echo "OK!";//$chmod o+rw galleries 

    }