将文件上传到数据库时出错。(php)

时间:2017-10-20 16:33:13

标签: php mysql file image-uploading

没有成功提交图片表单但不能使用图片。 在上传时,还将图像名称从k.jpg更改为37732-k.jpg 当我点击上传的图像名称所以它的节目编号和“2b2b2”这样的东西。请帮忙

****这是完整的PHP代码。**

<?php
include('../dbcon.php');
if (isset($_POST['submit'])) {

    $roll_no=$_POST['roll_no'];
    $name=$_POST['name'];
    $city=$_POST['city'];
    $std=$_POST['std'];
    $p_cont=$_POST['p_cont'];

    // $picture_type=$_FILES['image']['type'];
    // $imagename=$_FILES['image']['name'];
    // $tempname=$_FILES['image']['tmp_name'];


    // move_uploaded_file($tempname,"../dataimages/$imagename/");


$pic = rand(1000,100000)."-".$_FILES['image']['name'];
        $pic_loc = $_FILES['image']['tmp_name'];
        $folder="../dataimages/";
        if(move_uploaded_file($pic_loc,$folder.$pic))
        {
            ?><script>alert('successfully uploaded');</script><?php
        }
        else
        {
            ?><script>alert('error while uploading file');</script><?php
        } 


 $query="INSERT INTO `student`( `roll_no`, `name`, `city`, `p_cont`, `standerd`,'image') VALUES ('$roll_no','$name','$city','$std','$p_cont','$pic')";
$run=mysqli_query($con,$query);


if ($run == true) {

    ?>
    <script>
    alert('data inserted successfully');
    window.open('add_student.php','self');



    </script>

    <?php
} else{

?>
    <script>
    alert('data insertion failed');
    window.open('add_student.php','self');



    </script>
  <?php
}
}


?>

0 个答案:

没有答案