Jump to content
php.lv forumi

Upload picture


edw

Recommended Posts

Varbut vienkarsi, kads var pateikt, ka so sajugt

 

<form enctype="multipart/form-data" action="<?php echo $_SERVER['REQUEST_URI']; ?>" method="POST">

<p>Bilde: <input name="bilde" type="file"><br>
   <input type="submit" value="Pievienot">
</p>
</form>
<?php


$uploaddir = './test/';
$uploadfile = $uploaddir . basename($_FILES['bilde']['name']);

move_uploaded_file($_FILES['bilde']['tmp_name'], $uploadfile) 

?>

 

 

ar so

 

     <?php include"./dalas/db.php" ;?>
<?php

$tabula = "raksti";

$name = stripslashes($_POST['txtName']);
$message = stripslashes($_POST['txtMessage']);
$class = stripslashes($_POST['txtclass']);
$ip = $_SERVER['REMOTE_ADDR'];
$bilde = $_POST['bilde'];


if (!isset($_POST['txtName'])) {

   $query = "SELECT id, nosaukums, bilde, sadala, raksts, DATE_FORMAT(date, '%e/%m/%Y %H:%i') as newdate FROM $tabula ORDER BY id DESC";
   $result = mysql_query($query);


?>




<form method="post" action="<?php echo $_SERVER['REQUEST_URI']; ?>">


    <p>

   <p>
   <div align="center">

<table class="menu" width="520" height="250" border="0" cellpadding="0">
             <tr>
               <td class="menu" height="20" width="498">Pievienot jaunu rakstu</td>
             </tr>
             <tr>
             <td class="isaistxt" width="498" align="center">

       <table width="100%" height="100%" style="border-collapse: collapse" cellpadding="0" border="0">

   <tr>
     <td class="mid" width="133" height="27">

<p align="left">

<label for="txtName">Nosaukums:  </label>
       <td class="mid" width="376" height="27">


   <input type="text" title="Nosaukumu" name="txtName" size="36" /></tr>
     <tr>
     <td class="mid" width="133" height="27">

<label for="txtName">Sadaļa  </label>
       <td class="mid" width="376" height="27">


   <select size="1" name="txtclass">
<option>Sākums</option>
<option>Pakalpojumi</option>
<option>Kontakti</option>
</select></tr>
     </tr>
<tr>
     <td class="mid" width="133" height="27">

<p align="left">

<label for="bilde">Bilde:  </label>
       <td class="mid" width="376" height="27">



<input name="bilde" type="file">



</tr>

     </tr>
     <tr>
     <td class="mid" width="133" height="9">

     <label for="txtMessage">Raksts:  </label>
	<td class="mid" width="376" height="9">

  <script language="JavaScript" type="text/javascript" src="./rakstuforma/wysiwyg.js"></script> 



<textarea id="raksts" title="Raksts" name="txtMessage"></textarea>
<script language="JavaScript">
 generate_wysiwyg('raksts');
</script> </tr>
     <tr>
     <td class="mid" width="509" height="71" colspan="2" align="center">

     <label title="Pievienot">
   <input type="submit" value="Pievienot" /></label></table></td>
             </tr>
           	</table>


   </div>
   <br>




</form>

<?php
}

elseif (empty($name))  {
echo "Ievadi raksta nosaukumu!
Pēc 5 sekundē mēģini vēlreiz.
<meta http-equiv='refresh'content='5';>";
}
elseif (empty($message))  {
echo "Ievadi rakstu!<br>
Pēc 5 sekundē mēģini vēlreiz.
<meta http-equiv='refresh'content='5';>";
}


else {

   $query = "INSERT INTO $tabula SET raksts='$message', bilde='$bilde', nosaukums='$name', sadala='$class', date=NOW(), ip='$ip'";
   echo "Ieraksts tika veiksmīgi pievienots!";
   $result = mysql_query($query);

}

?>

 

 

kad panaku, lai fails tiek pievienots mape, nekas ieks db neparadas, un otradi, kad ieks db paradas, tad mape fails neparadas.

Edited by edw
Link to comment
Share on other sites

×
×
  • Create New...