Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/235.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 我的';移动上传的文件();不将我的图像移动到我指定的文件夹_Php - Fatal编程技术网

Php 我的';移动上传的文件();不将我的图像移动到我指定的文件夹

Php 我的';移动上传的文件();不将我的图像移动到我指定的文件夹,php,Php,检查您的目标文件夹权限。错误\u get\u last可能会给您一些提示,说明它为什么不起作用。检查这个 $targetFile=“userImages/$pid/”$_文件[“文件”][“名称”]; 如果(移动上传的文件($文件[“文件”][“tmp文件名”],$targetFile)){ echo“文件上传至:$target_文件””; }否则{ echo“移动上传文件失败!”; 打印(错误获取上次()); } 停止使用不推荐的mysql.*扩展,使用或替代;你的表单代码是什么?你是否启用了

检查您的目标文件夹权限。错误\u get\u last可能会给您一些提示,说明它为什么不起作用。检查这个

$targetFile=“userImages/$pid/”$_文件[“文件”][“名称”];
如果(移动上传的文件($文件[“文件”][“tmp文件名”],$targetFile)){
echo“

文件上传至:$target_文件”

”; }否则{ echo“

移动上传文件失败!

”; 打印(错误获取上次()); }
停止使用不推荐的
mysql.*
扩展,使用或替代;你的表单代码是什么?你是否启用了错误报告来获取更多信息,我实际上是php新手。我应该在哪里编码“error_get_last”?如果(移动上传的文件($_FILES[“file”][“tmp_name”],“userImages/$pid/”$_FILES[“file”][“name”]){echo”

文件上传到:$target_file

“;}否则{echo”

移动上传的文件失败!

“print_r(error_get_last())}是否应初始化$target\u文件的值?是。编辑我的答案以反映正确的代码位。error\u get\u last至少应该让您了解为什么移动不起作用。您可以使用它来实现正确的错误处理。
 <?php
    include("config.php");
    //Get the name of the input type submit
    if(ISSET($_POST['sign_up'])) {
        $username = trim($_POST['user']); 
        $password = trim($_POST['pass']);
        $gender=$_POST['gen'];
        $firstname =($_POST['first']); 
        $lastname = trim($_POST['last']);
        $y=$_POST['y'];
        $m=$_POST['m'];
        $d=$_POST['d'];
        $dob=$y."-".$m."-".$d;
        $imgpath=$_FILES['file']['name'];
        $imgFile = $_FILES['file']['name'];
        $tmp_dir = $_FILES['file']['tmp_name'];
        $imgExt = strtolower(pathinfo($imgFile,PATHINFO_EXTENSION));
        $valid_extensions = array('jpeg', 'jpg', 'png', 'gif'); 
        $userpic = rand(1000,1000000).".".$imgExt;      
        if(!empty($username) && !empty($password)) {
            $sql = mysql_query("SELECT * FROM users WHERE user_name = '$username'") or die(mysql_error());
            if(mysql_num_rows($sql) > 0) {
                $msg_error = "Username already registered!";
            } else {
                if(in_array($imgExt, $valid_extensions)){
                    mysql_query("INSERT INTO users
                             values('','$username','".MD5($password)."', '$gender', 
                                    '$dob', '$imgpath', 'guest', 
                                    '$firstname', '$lastname')")
                         or die(mysql_error()); 
                    $uuid=mysql_query("SELECT * FROM users");
                    while ($puid=mysql_fetch_array($uuid)){
                        $pid = $puid['user_id'];
                        mkdir("userImages/$pid");
                        move_uploaded_file($_FILES["file"]["tmp_name"], "userImages/$pid/" . $_FILES["file"]["name"]);
                    }
                    //image uploaded should be moved to my specified 
                    //folder after the code above is executed   

                    $_SESSION['sname']=$_POST['user'];
                    $msg_success = "You are now registered!";
                }
                else{
                    $msg_error = "Invalid image!";
                }
            }
        }else{
            $msg_error = "All fields are required!";
    }
}
?>
$targetFile = "userImages/$pid/" . $_FILES["file"]["name"];
if(move_uploaded_file($_FILES["file"]["tmp_name"], $targetFile)) { 
    echo "<P>FILE UPLOADED TO: $target_file</P>"; 
} else { 
    echo "<P>MOVE UPLOADED FILE FAILED!</P>"; 
    print_r(error_get_last()); 
}