dongqiao9583 2013-02-13 17:59
浏览 19
已采纳

我试图将一个文件上传到localhost,但没有工作

I´m trying to upload one file to the localhost server, but it doesnt work. I'm trying to give permissions to the folder where the file is to be located using chmod, but I do not get it. The form is printed dynamically in one file called index.php and, when the submit is clicked, the datas are recieved to the same php file called recExpediente.php.

PHP

    <? 
ini_set('error_reporting', E_ALL);

    require('conectaDemo.php');   

    if (is_uploaded_file($_FILES['Foto']['tmp_name'])) {
            $cSQL="SELECT NIF FROM CLIENTES WHERE ID_CLIENTE=?";
            $stmt=$oConni->prepare($cSQL) or die($oConni->error);
            $stmt->bind_param('i',$_POST['selDesc2']);
            $stmt->execute();                               
            $stmt->bind_result($DNI);
            if ($stmt->fetch()) {
                chmod('/var/www/pracRemesas/'.$DNI.'/', 0777);
                echo '/var/www/pracRemesas/'.$DNI.'/';
                $uploaddir='/var/www/pracRemesas/'.$DNI.'/';
             }
             $stmt->close();
            $uploadfile = $uploaddir . basename($_FILES['Foto']['name']); 
            move_uploaded_file($_FILES['Foto']['tmp_name'], $uploadfile);
            $cFoto=basename($_FILES['Foto']['name']);
            $xSQL = "INSERT INTO EXPEDIENTES (ID_CLIENTE, DOCUMENTO, 
            OBSERVACIONES) VALUES(?,?,?)";
            $stmt = $oConni->prepare($xSQL);
            $stmt->bind_param('iss', $_POST['selDesc2'], $cFoto, $_POST['observ']);
            $stmt->execute();
            $stmt->close();

}


   if (isset($_POST['newid'])) {  
            $cSQL="SELECT ID_CLIENTE, NOMBRE FROM CLIENTES";
            $stmt=$oConni->prepare($cSQL) or die($oConni->error);
            $stmt->execute();                               
            $stmt->bind_result($ID_CLIENTE, $NOMBRE);
            echo'<form name="nuevoExp" id="frmLogin" action="recExpediente.php" method="POST" enctype="multipart/form-data">';
            echo'<select id="selDesc2" name="selDesc2">';
            echo'<option value=-1>Seleccione cliente</option>';
             while ($stmt->fetch()) {
                echo'<option value="'.$ID_CLIENTE.'">'.$NOMBRE.'</option>';
            }   
            $stmt->close();
            echo'</select><br>'; 
            echo'<input type="file" name="Foto" id="Foto"><br>';
            echo'Observaciones<input type="text" name="observ" id="observ"><br>';
            echo'<input  type="submit" name="butEnv" id="butEnv" value="Enviar"/>';
            echo'</form>';
}?>
  • 写回答

1条回答 默认 最新

  • dongtieshang5429 2013-02-13 18:35
    关注

    Your problem is variable scope. You define $uploaddir in an if statement where it will live only for that statement. You need to define it before and you can modify it inside the if statement.

    This is causing your code to actually be

    $uploadfile = basename($_FILES['Foto']['name']);
    

    I suggest more checks in your code and fail safes. You can include the upload code and your insert in the if ($stmt->fetch()) {. If you move everything in the if statement, you wont have to change anything for the $uploaddir issue.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 想问一下树莓派接上显示屏后出现如图所示画面,是什么问题导致的
  • ¥100 嵌入式系统基于PIC16F882和热敏电阻的数字温度计
  • ¥15 cmd cl 0x000007b
  • ¥20 BAPI_PR_CHANGE how to add account assignment information for service line
  • ¥500 火焰左右视图、视差(基于双目相机)
  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号