简体   繁体   English

上传图像php mysql二进制

[英]uploading images php mysql binary

Hi guys I keep getting an error no image selected when I try and upload, the upload form is definitely the right name and id same for the upload so it must be something wrong with the code, can anyone see why? 嗨,大家好,我尝试上传时仍然没有选择任何图片,上传表单的名称和ID确实与上传相同,因此代码一定有问题,有人可以看到原因吗?

<?php


// Create MySQL login values and 
// set them to your login information.
$username = "**";
$password = "**";
$host = "**";
$database = "**";

// Make the connect to MySQL or die
// and display an error.
$link = mysql_connect($host, $username, $password);
 if (!$link) {
      die('Could not connect: ' . mysql_error());
   }

   // Select your database
    mysql_select_db ($database);  

     session_start();
     if(!isset($_SESSION['username']))
    {
          die('You have no access to this page.');
    }
  else{
  $username = $_SESSION['username'];
   // Make sure the user actually 
   // selected and uploaded a file
    if (isset($_FILES['image']) && $_FILES['image']['size'] > 0) { 

  // Temporary file name stored on the server
  $tmpName  = $_FILES['image']['tmp_name'];  

  // Read the file 
  $fp      = fopen($tmpName, 'r');
  $data = fread($fp, filesize($tmpName));
  $data = addslashes($data);
  fclose($fp);


  // Create the query and insert
  // into our database.
  $query = "INSERT INTO Members WHERE username = '$username' ";
  $query .= "(image) VALUES ('$data')";
  $results = mysql_query($query, $link);

  // Print results
  print "Thank you, your file has been uploaded.";

 }
else {
 print "No image selected/uploaded";
 }
 }
  // Close our MySQL Link
  mysql_close($link);
  ?>  

Probably your <form> tag lacks enctype parameter. 您的<form>标记可能缺少enctype参数。 It should look like this: 它看起来应该像这样:

<form action="index.php?action=upload" method="post" enctype="multipart/form-data">

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM