2017-04-01 14 views
-1
を使用してフォルダに入れていない

IAMがPHPとMySQLを使用してフォルダ内の画像を挿入しようとしているが、画像がデータベース ならびにフォルダに保存されていないこれは私のPHPコードである画像は、PHPとMySQL

if(isset($name)) { 
$pass = base64_encode($pass); 
$cpass = base64_encode($cpass); 
$image_name = $_FILES['image']['name']; 
$image_temp = $_FILES['image']['tmp_name']; 
$image_type = $_FILES['image']['type']; 
if ($image_type == 'image/png' || $image_type == 'image/jpg' || $image_type == 'image/iso' || $image_type = 'image/gif') { 
    $upload = move_uploaded_file('uploads1/' . $_FILES['image']['name']); 
     if($upload) { 
      $reg_query = mysqli_query($conn, "INSERT INTO `quiz_register`(`name`, `email`, `mobile`, `password`, `cpassword`, `image`) VALUES ('$name','$mail','$cell','$pass','$cpass','$image_name')"); 
      if ($reg_query) { 
       echo 'success'; 
      } else { 
       echo 'fail'; 
      } 
     } 
    } 
} 

これは私のHTMLコード

 <form method="post" action="" enctype="multipart/form-data"> 
     <input type="text" name="name" placeholder="name" class="form-control" id="name"> <br> 
     <input type="email" name="mail" placeholder="[email protected]" class="form-control" id="mail"> <br> 
     <input type="text" name="mobile" placeholder="Mobile" class="form-control" id="mobile"> <br> 
     <input type="password" name="password" placeholder="password" class="form-control" id="password"> <br> 
     <input type="password" name="cpassword" placeholder="confirm-password" class="form-control" id="cpassword"> <br> 
     <input type="file" name="image" id="file" class="form-control" required> <br> 
</form> 

です

答えて

0

最近これを行っています。ここで私が使用して、それはそれはあなたに役立つかもしれないあなたは、このコードをチェック魅力

$binary=base64_decode($file); 
$file = fopen('../newSite/profileImages/'.$filename, 'wb'); 
// Create File 
$is_written = fwrite($file, $binary); 
fclose($file); 

if($is_written > 0) { 

    $connection = mysqli_connect('localhost', 'username', 'pass','db name'); 

      $query = "UPDATE users SET image = '$filename' WHERE id = '$user_id';"; 

    $result = mysqli_query($connection, $query) ; 

    if($result){ 
     echo "success"; 
    }else{ 
     echo "failed"; 
    } 

    mysqli_close($connection); 
} 
0
<?php 

     if(isset($_POST['submit'])) 
     { 
     $filename=$_FILES['image']['name']; 
     $filetempname=$_FILES['image']['tmp_name']; 
     $fname=md5($_SERVER['REMOTE_ADDR'].rand()).$filename; 
     $filepath="uploads/uploads1/".$fname; 
     $upload=move_uploaded_file($filetempname,$filepath1); 
if($upload) { 
      $reg_query = mysqli_query($conn, "INSERT INTO `quiz_register`(`name`, `email`, `mobile`, `password`, `cpassword`, `image`) VALUES ('$name','$mail','$cell','$pass','$cpass','$filepath')"); 
      if ($reg_query) { 
       echo 'success'; 
      } else { 
       echo 'fail'; 
      } 
     } 
?> 

のように働いたものです。

+1

このコードは、私はあなたのコードが、ときIAM挿入を試みたあなた –

+0

に便利です、画像列がquiz_registerテーブルに空白表示され、残りの値は、あなたが$ filepath1を使用するイメージ名を入力し、画像 –

+0

以外挿入している私は、更新しています私のコード –

0
just reviewed your code i think the following code could work you please go through it and let me know if there is some issue.. 

<?php 
$con = mysqli_connect("localhost","root","","test"); 


if(isset($_POST['submit'])) 
{ 
     $pass = base64_encode($_POST['password']); 
     $cpass = base64_encode($_POST['cpassword']); 
     $name=$_POST['name']; 
     $mail=$_POST['mail']; 
     $cell=$_POST['mobile']; 
     $image_name = $_FILES['image']['name']; 
     $image_temp = $_FILES['image']['tmp_name']; 
     $image_type = $_FILES['image']['type']; 
     if ($image_type == 'image/png' || $image_type == 'image/jpg' ||       $image_type == 'image/iso' || $image_type = 'image/gif') 
    { 
     $upload = move_uploaded_file($_FILES["image"]["tmp_name"],'uploads1/' . $_FILES['image']['name']); 
     if($upload) 
     { 
      $reg_query = mysqli_query($con, "INSERT INTO `quiz_register`(`name`, `email`, `mobile`, `password`, `cpassword`, `image`) VALUES ('$name','$mail','$cell','$pass','$cpass','$image_name')"); 
      if ($reg_query) { 
       echo 'success'; 
      } else { 
       echo 'fail'; 
      } 
     } 
    } 
} 
?> 
関連する問題