Jump to content
php.lv forumi

upload file and data insert in mysql


ziedinjsh

Recommended Posts

Sveiki.

 

Šādi izskatās kods:

<?php
include "misc/config.php";
if (isset($_POST['get_photo'])) {

// faila detaljas
$p_name = $_FILES["photo"]["name"];
$p_type = $_FILES["photo"]["type"];
$p_size = $_FILES["photo"]["size"];
$p_temp = $_FILES["photo"]["tmp_name"];
$p_error = $_FILES["photo"]["error"];
$p_date = date("y-m-d");

if($p_error > 0)
  die ("photo culd not uploaded! Code: $p_error");

 else {

 //Faila nosaciijumi
 if($p_type == "application/octet-stream" || $p_size >3145728) {
 die("this format is not allowed or file is to big");
 }
 else
 {

$query = mysql_query("INSERT INTO photos (p_name, p_type, p_size, p_date) VALUES ('','$p_name','$p_type','$p_size','$p_date') ");
 move_uploaded_file($p_temp,"uploads/".$p_name);
  echo "photo uploaded!";
  }
}	







}
echo "<form method='post' action='".$_SERVER['PHP_SELFE']."' enctype='multipart/form-data'>";
echo "<input type='file' name='photo'>";
echo "<input type='submit' value='Upload' name='get_photo'>";
echo "</form>";
?>

 

failu viņš augšupielādē, bet informāciju datubāzē neieliek.. kas nav pareizi?

 

kur man jālike md5(); funkcija lai augšupielādējot faili viņš būtu nokodēts ar md5(); un paliktu faila formāts?

 

meiģināju šādi:

$p_name = md5($_FILES["photo"]["name"]);

failu viņš nokodēja ar md5 bet fomāts galā nebija

 

varbūt ir kāds gatavs kods kur datus ieliek mysql un var augšupielādēt tikai bilžu failus ar md5(); funkciju?

Link to comment
Share on other sites

$query = mysql_query("INSERT INTO photos (p_name, p_type, p_size, p_date) VALUES ('','$p_name','$p_type','$p_size','$p_date') ");

 

"photos" noraada 4 laukus bet VALUES ir 5. Taa varbuut probleema? Tu saki "informāciju datubāzē neieliek" - vai kaadu sql kljuudu nemet esi skatiijies ?

Link to comment
Share on other sites

Šāds ir kods:

<?php
error_reporting(E_ALL);
include "misc/config.php";



if (isset($_POST['get_photo'])) {


// faila detaljas
$p_name = $_FILES["photo"]["name"];
$p_type = $_FILES["photo"]["type"];
$p_size = $_FILES["photo"]["size"];
$p_temp = $_FILES["photo"]["tmp_name"];
$p_error = $_FILES["photo"]["error"];
$p_date = date("Y-m-d");
$p_time = time("H:i:s");


if($p_error > 0)
  die ("photo culd not uploaded! Code: $p_error");

 else {

 //Faila nosaciijumi
   if($p_type == "application/octet-stream" || $p_size >3145728) {
 die("this format is not allowed or file is to big");

 }
 else
 {

$query = mysql_query("INSERT INTO photos (p_name, p_type, p_size, p_date, p_time) VALUES ('$p_name','$p_type','$p_size','$p_date', 'p_time') ");
 move_uploaded_file($p_temp,"uploads/".$p_name);
  echo "photo uploaded!";
  }
}	




}
echo "<form method='post' action='".$_SERVER['PHP_SELF']."' enctype='multipart/form-data'>";
echo "<input type='file' name='photo'>";
echo "<input type='submit' value='Upload' name='get_photo'>";
echo "</form>";

?>

viņš augšupielādē bildi iek uploads foldera.. un ieliek datus iekš mysql.

 

Tātad.. Kā varētu uztaisīt tā kad augšupielādējas bilde un arī taj pašai bildei izveidojas thumbnail iekš uploads/small

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...