içerik başarılı bir şekilde gönderiliyor ama resim olayını tam anlamıyla yapamadım.
Resimleri upload ediyor fakat link yapısı sef olmuyor resim açılmıyor.
Sistem Wordpress
Eklentisiz içerik girilmesi resim yüklemeli yapmak istediğim
<?php
get_header();
/*
Template Name: Tarif Ekle
*/
?>
<style type="text/css" media="screen">
#yukleyici {
padding:10px;
position:absolute;
width:auto;
}
#sonuc {
padding:10px;
position:absolute;
left:0;
bottom:0;
}
.olumlu, .olumsuz {
width:300px;
border-radius:5px;
padding:10px;
margin:3px;
color:#00CC33;
text-align:center;
}
.olumsuz {
color:#900;
}
#kutu {
cursor:pointer;
position:absolute;
padding:10px;
top:0;
left:0;
text-align:center;
}
#yuklenen {
position:absolute;
width:250px;
max-height:75%;
overflow:auto;
padding:10px;
bottom:0;
left:0;
text-align:center;
}
#Form input.txt {
color: #A0522D;
background-color: #F8F8F8;
border: 1px solid #CDCDCD;
width:200px;
}
#Form textarea.txt {
color: #A0522D;
background-color: #F8F8F8;
border: 1px solid #CDCDCD;
}
#Form input.btn {
color: #B22222;
background-color: #F1F1F1;
border: 1px solid #C2C2C2;
font-weight:bold;
margin-right: 15px;
}
#Form p {
margin: 0;
padding: 5px 0 0 10px;
}
#Form p label {
float: left;
font-weight: bold;
color: #C13C3C;
width: 120px;
}
</style><script>
var input_say = <?php if(isset($_GET['input'])): echo $input_say = $_GET['input']; else: echo $input_say ='1'; endif; ?>;
function ekle(){
var yeni = document.createElement('input');
var eksi = document.createElement('a');
var br = document.createElement('br');
yeni.setAttribute('type','file');
yeni.setAttribute('name','resim'+input_say);
yeni.setAttribute('id','input'+input_say);
eksi.setAttribute('href','#');
eksi.setAttribute('id','eksi'+input_say);
eksi.setAttribute('onclick',"cikart('"+input_say+"')");
eksi.innerHTML = '[-]';
br.setAttribute('id','br'+input_say);
document.getElementById('inputlar').appendChild(yeni);
document.getElementById('inputlar').appendChild(eksi);
document.getElementById('inputlar').appendChild(br);
input_say++;
document.getElementById('yazi-ekle').setAttribute('action','?yukle&input='+input_say);
}
function cikart(i){
document.getElementById('inputlar').removeChild(document.getElementById('eksi'+i));
document.getElementById('inputlar').removeChild(document.getElementById('br'+i));
document.getElementById('inputlar').removeChild(document.getElementById('input'+i));
if(input_say > 0) {input_say--;}
document.getElementById('yazi-ekle').setAttribute('action','?yukle&input='+input_say);
}
</script>
<div id="Form">
<form id="yazi-ekle" action="?yukle&input=<?=$input_say?>" method="post"enctype="multipart/form-data" name="yazi_ekle">
<p>
<label for="in1">BaÅlık : </label>
<input type="text" name="baslik" id="in1" class="txt" />
</p>
<p>
<label for="in2">Etiketler : </label>
<input type="text" name="etiketler" id="in2" placeholder="Etiketler(virgülle ayırınız)(opsiyoneldir)" class="txt" />
</p>
<p>
<label for="in4">İçerik : </label>
<textarea class="txt" id="in4" name="icerik" cols="41" rows="10"></textarea>
</p>
<p>
<label for="in4">Kategori : </label>
<?php wp_dropdown_categories('show_count=1&hierarchical=1&name=kategori'); ?>
</p>
<p><label for="in4">Resim : </label></p>
<div id="inputlar">
<input type="file" name="resim0" /><br />
<?php
if (isset($_GET['input'])):
$i = 1;
while($i<$_GET['input']){
echo '<input type="file" id="input'.$i.'" name="resim'.$i.'" /><a href="#" id="eksi'.$i.'" onclick="cikart(\''.$i.'\')">[-]</a><br id="br'.$i.'" />';
$i++;
}
endif;
?>
</div>
<input type="button" onClick="ekle()" value="Ekle [+]" /> |
<p>
<label> </label>
<input type="submit" value="gonder" class="btn" name="gonder" />
</p> <label> </label></p>
</p>
</form>
<div id="sonuc">
<?php
if(isset($_GET['yukle'])) {
$say = 0;
foreach ($_FILES as $input => $deger)
{
if(!empty($_FILES[$input]["name"])){
if ((($_FILES[$input]["type"] == "image/gif") || ($_FILES[$input]["type"] == "image/jpeg") || ($_FILES[$input]["type"] == "image/png")) && ($_FILES[$input]["size"] < 2097152)){
if ($_FILES[$input]["error"] > 0){ echo '<div class="olumsuz">Hata kodu: '.$_FILES[$input]["error"]; } else {
if (file_exists("resimler/".$_FILES[$input]["name"])){ echo '<div class="olumsuz">Daha önce yüklenmiÅ.'; } else {
move_uploaded_file($_FILES[$input]["tmp_name"],"resimler/".$_FILES[$input]["name"]);
echo '<div class="olumlu">Resim yüklendi.';
}
}
} else{ echo '<div class="olumsuz">Dosya türü resim olmalı ve 2 MB dan küçük olmalıdır.';}
echo ' ('.mb_substr($_FILES[$input]["name"],0,30,'UTF-8').')</div>';
$say ++;
}
}
if($say==0){echo '<div class="olumsuz">Hiç dosya seçilmedi.</div>';};
}
?>
</div>
<?php
if($_POST["gonder"]) {
$baslik = $_POST["baslik"];
$icerik = $_POST["icerik"];
$etiketler = $_POST["etiketler"];
$kategori = $_POST["kategori"];
$tarih = date("Y-m-d H:i:s");
if($baslik == "" or $icerik == "") {
$hata = "Lütfen baÅlı veya içerik giriniz";
echo $hata;
} else {
$yazi = array(
'post_title' => $baslik,
'post_content' => $icerik,
'tags_input' => $etiketler,
'post_category' => array($kategori),
'post_status' => 'pending',
'post_date' => $tarih
);
$yazi_id = wp_insert_post( $yazi );
if($yazi_id) {
echo "Tebrikler yazı gönderildi";
}
}
}
?>
</div><!-- /yazi-ekle-form -->
<?php get_sidebar(); ?>
<?php get_footer(); ?>