dtgta48604 2019-05-15 08:00
浏览 44

move_uploaded_file函数没有上传到服务器[重复]

This question already has an answer here:

file is not uploading into my server, I am using move_uploaded_file function, i got output as Your file was uploaded successfully. but file is not thare in that location.

image.html

<script>
$(document).ready(function(){
    $(document).on('change', '#profile_photo', function(){
        var file_data = $('#profile_photo').prop('files')[0]['name']; 
        var email_id=document.getElementById('email_id').value;
        var filename=document.getElementById('profile_photo').files[0]['name'];
        form_data.append('file', document.getElementById('profile_photo').files[0]);

        $.ajax({
                url:"https://imageupload.php",
                method:"POST",
                data:({'file':filename,'email_id':email_id }),
                beforeSend:function(){
                    $('#uploaded_image').html("<label class='text-success'>file Uploading...</label>");
                },   
                success:function(data) {
                    $('#uploaded_image').html(data);
                }
            });
        });
});
</script>

imageupload.php

<?php
$filename=$_POST['file'];
$email_id=$_POST['email_id'].substr($filename, -5);

if(file_exists("upload/" . $email_id)){
    echo  $filename . " is already exists.";
} else{
    move_uploaded_file($filename, "upload/" .  $email_id);
    echo $email_id."Your file was uploaded successfully.";
}
?>
</div>
  • 写回答

1条回答 默认 最新

  • dqzg62440 2019-05-15 08:04
    关注

    imageupload.php Try Code below and make sure you set uploads folder permission to 777.

    <?php
    $filename=$_POST['file']['name'];
    $tmppath = $_FILES['file']['tmp_name'];
    
    $email_id=$_POST['email_id'].substr($filename, -5);
    if(file_exists("upload/" . $email_id)){
        echo  $filename . " is already exists.";
    } else{
        move_uploaded_file($tmppath, "upload/".$email_id);
        echo $email_id."Your file was uploaded successfully.";
    }
    ?>
    
    评论

报告相同问题?

悬赏问题

  • ¥15 关于大棚监测的pcb板设计
  • ¥15 stm32开发clion时遇到的编译问题
  • ¥15 lna设计 源简并电感型共源放大器
  • ¥15 如何用Labview在myRIO上做LCD显示?(语言-开发语言)
  • ¥15 Vue3地图和异步函数使用
  • ¥15 C++ yoloV5改写遇到的问题
  • ¥20 win11修改中文用户名路径
  • ¥15 win2012磁盘空间不足,c盘正常,d盘无法写入
  • ¥15 用土力学知识进行土坡稳定性分析与挡土墙设计
  • ¥70 PlayWright在Java上连接CDP关联本地Chrome启动失败,貌似是Windows端口转发问题