wie speichert hochgeladene Bild in Datenbank mit php

Hallo, den folgenden code schreiben, hochladen und speichern, hochgeladenes Bild in der Datenbank, aber nicht die Arbeit , bitte helft mir !!

Datei 1:

      <form action="upload.php" method="post" enctype="multipart/form-data" target="upload_target" onsubmit="startUpload();" >

                <label>File:  
                <input name="myfile" type="file" size="30" />
                </label>

                <input type="submit" name="submitBtn" class="sbtn" value="Upload" />


                  <iframeid="upload_target"name="upload_target"src="#"style="width:0;height:0;border:0px solid #fff;"></iframe>
                </form>
                </div>

Datei 2:

<?php




   //Edit upload location here
   $destination_path = getcwd().DIRECTORY_SEPARATOR;
   $target_path="my/";
   $result = 0;
   $name=$_FILES['myfile']['name'];
   $target_path = $target_path . basename( $_FILES['myfile']['name']);

   if(@move_uploaded_file($_FILES['myfile']['tmp_name'], $target_path)) {
   list($width, $height, $type, $attr) = getimagesize($target_path);
echo "Image width " .$width;
echo "<BR>";
echo "Image height " .$height;
echo "<BR>";
echo "Image type " .$type;
echo "<BR>";
echo "Attribute " .$attr;


      $result = 1;
   }

  //sleep(1);




$link=mysql_connect('localhost','root','');
if(!$link)
{die('you cannot connect to database...');}
$db=mysql_select_db('final');
if(!$db)die('smile');

if (isset($_FILES['myfile']) && $_FILES['myfile']['size'] > 0) {

//define the posted file into variables 
$name = $_FILES['myfile']['name']; 
$tmp_name = $_FILES['myfile']['tmp_name']; 
$type = $_FILES['myfile']['type']; 
$size = $_FILES['myfile']['size']; 

//if your server has magic quotes turned off, add slashes manually 
//if(!get_magic_quotes_gpc()){ 
//$name = addslashes($name); 
//} 

//open up the file and extract the data/content from it 
$extract = fopen($tmp_name, 'r'); 
$content = fread($extract, filesize($tmp_name)); 
$content = addslashes($content); 
fclose($extract);  

//connect to the database 


//the query that will add this to the database 
$s=mysql_query("SET NAMES 'utf8'");
$sql = "INSERT INTO `final`.`products` (`Productcode`, `Productname`, `Price`,`Descriptionofgood`, `image`) VALUES ('','','','','".$target_path."') WHERE `products`.`Productcode`='1371' ";
$results = mysql_query($sql);
if(!$result)die('not');
}

?>
Erste, Sie benötigen, zu korrigieren die Probleme mit Ihrem html. Sie haben diese iframeid="upload_target" was Platz spart, aber es ist nicht corect. Fügen Sie ein Leerzeichen zwischen den Tags und die id, wie z.B.: iframe id="upload_target"
Was soll ich als Nächstes tun gewinnend

InformationsquelleAutor Darya | 2013-06-29

Schreibe einen Kommentar