Hello, I have a problem with image upload.
Normal script should upload the image and modify the table in mysql.
But when I upload the image, it does not up on the server and do not write rows in mysql.
The script is for image & virtual tour, my priority is upload photo, not virtual tour.
PLEASE…HELP
This is php & html code:
[embed=425,349]<?php
require_once(‘includes/config.php’);
include ‘db/connect.php’;
include ‘db/functions.php’;
if(!isset($_SESSION[‘login’])) $_SESSION[‘login’] = ‘No’;
if($_SESSION[‘login’] != ‘Yes’)
{
echo ‘’;}
else
{
if(isset($_GET[‘id’])){$last_id=$_GET[‘id’];}
$error_image=’’;
$error_tur=’’;
if(isset($_POST[‘action’]) AND $_POST[‘action’]==‘load’){
$directory="./upload_photos/$last_id";
$filesize1=$HTTP_POST_FILES[‘ufile1’][‘size’][0];
$filesize2=$HTTP_POST_FILES[‘ufile2’][‘size’][0];
$path1= “…/admin/upload_photos/$last_id/images/”.$HTTP_POST_FILES[‘ufile1’][‘name’][0];
$path2= “…/admin/upload_photos/$last_id/virtual_tour/”.$HTTP_POST_FILES[‘ufile2’][‘name’][0];
$path3= “…/admin/upload_photos/$last_id/thumbnails/”.$HTTP_POST_FILES[‘ufile1’][‘name’][0];
if(!file_exists($directory))
{
mkdir("…/admin/upload_photos/$last_id");
chmod("…/admin/upload_photos/$last_id", 0777);
mkdir("…/admin/upload_photos/$last_id/images");
chmod("…/admin/upload_photos/$last_id/images", 0777);
mkdir("…/admin/upload_photos/$last_id/thumbnails");
chmod("…/admin/upload_photos/$last_id/thumbnails", 0777);
mkdir("…/admin/upload_photos/$last_id/virtual_tour");
chmod("…/admin/upload_photos/$last_id/virtual_tour", 0777);
}
if(isset($HTTP_POST_FILES[‘ufile1’][‘name’][0]) AND ($HTTP_POST_FILES[‘ufile1’][‘name’][0]!=’’))
{ if (!file_exists("…/admin/upload_photos/$last_id/images/".$HTTP_POST_FILES[‘ufile1’][‘name’][0])
AND ($filesize1!=0))
{
if(‘jpg’== strtolower(substr($HTTP_POST_FILES[‘ufile1’][‘name’][0], strrpos($HTTP_POST_FILES[‘ufile1’][‘name’][0], ‘.’) + 1)))
{
$query0 =(mysql_query( "SELECT * FROM imagini WHERE id2='$last_id'"));
if (mysql_num_rows($query0) < 1)
{
//copy file to where you want to store file
include 'watermark.php';
include 'thumbnails.php';
/////////////////////////////////////
//copy($HTTP_POST_FILES['ufile1']['tmp_name'][0], $path1);
insertUploadImage($last_id,$path1,$path3,1);
$error_image="Image <strong> ".$HTTP_POST_FILES['ufile1']['name'][0]." </strong> was loaded successfully <br/>";
}
else{
include 'watermark.php';
include 'thumbnails.php';
//copy($HTTP_POST_FILES['ufile1']['tmp_name'][0], $path1);
insertUploadImage($last_id,$path1,$path3,0);
$error_image="Image <strong> ".$HTTP_POST_FILES['ufile1']['name'][0]." </strong> was loaded successfully <br/>";
}
}
else {$error_image="Only .jpg extension<br/>";}
}
else {$error_image="Image with name <strong> ".$HTTP_POST_FILES['ufile1']['name'][0]." </strong> exist on server<br/>";}
}
if(!file_exists($directory))
{
mkdir("../admin/upload_photos/$last_id");
chmod("../admin/upload_photos/$last_id", 0777);
mkdir("../admin/upload_photos/$last_id/images");
chmod("../admin/upload_photos/$last_id/images", 0777);
mkdir("../admin/upload_photos/$last_id/thumbnails");
chmod("../admin/upload_photos/$last_id/thumbnails", 0777);
mkdir("../admin/upload_photos/$last_id/virtual_tour");
chmod("../admin/upload_photos/$last_id/virtual_tour", 0777);
}
if(isset($HTTP_POST_FILES['ufile2']['name'][0]) AND ($HTTP_POST_FILES['ufile2']['name'][0]!='') )
{if (!file_exists("../admin/upload_photos/$last_id/virtual_tour/".$HTTP_POST_FILES['ufile2']['name'][0])
AND ($filesize2!=0))
{
if('jpg'== strtolower(substr($HTTP_POST_FILES['ufile2']['name'][0], strrpos($HTTP_POST_FILES['ufile2']['name'][0], '.') + 1)))
{
$query =(mysql_query( "SELECT id FROM virtual_tour WHERE id='$last_id'"));
if (mysql_num_rows($query) < 1)
{
if($_POST['link']==''){$link_tur="http://google.ro";}
else{$link_tur=$_POST['link'];}
//copy file to where you want to store file
copy($HTTP_POST_FILES['ufile2']['tmp_name'][0], $path2);
insertUploadTur($last_id,$path2,$link_tur);
$error_tur="Image <strong> ".$HTTP_POST_FILES['ufile2']['name'][0]." </strong> was loaded successfully <br/>";
}
else{
while($row = mysql_fetch_array($query))
{
if($row['id']!=$last_id)
{
if($_POST['link']==''){$link_tur="http://google.ro";}
else{$link_tur=$_POST['link'];}
//copy file to where you want to store file
copy($HTTP_POST_FILES['ufile2']['tmp_name'][0], $path2);
insertUploadTur($last_id,$path2,$link_tur);
$error_tur="Image <strong> ".$HTTP_POST_FILES['ufile2']['name'][0]." </strong> was loaded successfully <br/>";
}
else{$error_tur="Image exist.<br/>";break;}
}
}
}
else {$error_tur="Only .jpg extension";}
}
else {$error_tur="Image with name <strong>".$HTTP_POST_FILES['ufile2']['name'][0]." </strong>exist on server. <br/>";}
}
}
///////////////////////////////////////////////////////
echo’
echo’
echo $error_image;echo'</br>';
echo $error_tur; echo'</div>';
echo'<table class="uploadeuri" width="600" border="0" align="center" cellpadding="0" cellspacing="1">
<tr>
<form action="images.php?id='.$last_id.'" method="post" enctype="multipart/form-data" name="form1" id="form1">
<input type="hidden" name="action" value="load" /></td>
<input type="hidden" name="v_position" value="bottom" /></td>
<input type="hidden" name="h_position" value="right" /></td>
<input type="hidden" name="wm_size" value=".15" /></td>
<input type="hidden" name="watermark" value="../admin/images/watermark.png" /></td>
<td>
<table width="100%" align="left" border="0" cellpadding="3" cellspacing="1" bgcolor="#FFFFFF">
<tr>
<th colspan="2"><strong>Upload pentru imagini</strong></td>
</tr>
<tr>
<td><strong>Description image</strong> </td>
<td><input size="50" type="text" name="description_image" value="" /></td>
</tr><tr>
<td><strong>Select image</strong></td>
<td><input name="ufile1[]" type="file" size="50" /></td>
</tr>
<tr>
<th colspan="2">
<strong>Upload for virtual tour</strong>
</th>
</tr>
<tr>
<td><strong>Image virtual tour</strong></td>
<td><input name="ufile2[]" type="file" size="50" /></td>
</tr>
<tr>
<td><strong>Link virtual tour</strong> </td>
<td><input size="50" type="text" name="link" value=" http://mylink/admin/upload_photos/'.$last_id.'/virtual_tour/" /></td>
</tr>
<tr>
<td></td>
<td align="left"><input class="upload_image" type="submit" name="Submit" value="Upload" /></td>
</tr>
</table>
</td>
</form>
</tr>
</table>
<form action="images.php?action=modif" method="post" enctype="multipart/form-data" >
<table class="table_with_images" width="800" border="0" cellpadding="0" cellspacing="1" align="center">';
// if(isset($_POST['action']) AND $_POST['action']=='load'){
if(file_exists("../admin/upload_photos/$last_id/images"))
{
echo'<tr><th class="upload_complete" colspan="6">Images was uploaded</th></tr>';
if ($handle = opendir("../admin/upload_photos/$last_id/images")) {
while (false !== ($file = readdir($handle))) {
if ($file != "." && $file != "..") {
echo "
<tr>
<td class='name_image' >$file</td>
</tr>
<tr>"; $modif_row=selectImage($last_id,$file);
echo'
<td><a href="'.$modif_row['link_image'].'" title="Preview"><img src="'.$modif_row['link_thumb'].'" ></a></td>
<td><a class="tooltip" title="Primary photo" ><div class="menu_pic55" id_photo="'.$modif_row['id_photo'].'" id="'.$modif_row['id2'].'" file="'.$file.'" type="images" description="'.$modif_row['description_image'].'">';
if($modif_row['first_photo']==1){echo'<img src="images/primary_photo.jpg" alt="Set primary photo"></div></a> </td>';}
else{echo'<img src="images/priamry_photo_activa.jpg" alt="Set primary photo"></div></a> </td>';}
echo'
<td><strong>Description</strong> <input size="40" id="in'.$modif_row['id_photo'].'" type="text" name="description" value="'.$modif_row['description_image'].'" /></td>
<td><a class="tooltip" title="Apply desc modify"><div class="menu_pic44" id_photo="'.$modif_row['id_photo'].'" id="'.$modif_row['id2'].'" file="'.$file.'" type="images" description="'.$modif_row['description_image'].'"><img src="images/modify_description2.jpg" alt="Preview image"></div></a> </td>
<td><a class="tooltip" title="Preview image" href="'.$modif_row['link_image'].'"><img src="images/preview_photo.jpg" alt="Preview image"></a></td>
<td><a class="tooltip" title="Delete image"><div class="menu_pic22" id="'.$modif_row['id2'].'" file="'.$file.'" type="images"><img src="images/delete_photo.jpg" alt="Delete image"></div></a> </td>
';
echo"</td></tr>
<tr>
<th class='pause_rows' colspan='6'><hr/></th>";
echo'</tr>';
}
}
closedir($handle);
}
echo'
</table>';
echo'
<table class="table_with_images" width="800" border="0" cellpadding="0" cellspacing="1" align="center">
<tr><th class="upload_complete" colspan="6">Preview virtual tour</th></tr>';
if ($handle = opendir("./upload_photos/$last_id/virtual_tour")) {
while (false !== ($file2 = readdir($handle))) {
if ($file2!= "." && $file2 != "..") {
echo "<tr>
<td class='name_image'>$file2</td>
<td>"; $modif_row2=selectTur($last_id,$file2);
echo'
</tr><tr> <td><a href="'.$modif_row2['photo_tour'].'" title="Preview"><img src="'.$modif_row2['photo_tour'].'" height="80px" width="310px"></a></td>
<td><strong>Link tur virtual</strong> <input size="40" id="tur'.$modif_row2['id'].'" type="text" name="description" value="'.$modif_row2['link_tur'].'" /></td>
<td><a class="tooltip" title="Modify link" ><div class="menu_pic44" id="'.$modif_row2['id'].'" file="'.$file2.'" type="virtual_tour"><img src="images/modify_description2.jpg" alt="Modify link"></div></a> </td>
<td><a class="tooltip" title="Preview image" href="'.$modif_row2['photo_tour'].'"><img src="images/preview_photo.jpg" alt="Preview image tour"></a></td>
<td><a class="tooltip" title="Delete virtual tour" ><div class="menu_pic22" id="'.$modif_row2['id'].'" file="'.$file2.'" type="virtual_tour"><img src="images/delete_photo.jpg" alt="Delete image"></div></a> </td>
<td><hr/></td>
</tr>';
}
}
closedir($handle);
}
}
echo '
<th class="pause_rows" colspan="6"><hr/></th>
</table>
</form>';
$the_result = mysql_query(selectID($last_id)) or die("Eroare: ".mysql_error());
if($rowe = mysql_fetch_array($the_result)){
$id=$rowe['id'];
echo "
<div class='ad_success'>
<ul>
<li><a href='index.php'><img src='images/back_to_admin.jpg' alt='Click for go to admin page' /><span>Click for go to admin page</span></a></li>
<li>
<a target=_blank'' href='";
if ($rowe['category']=="Apartament") {
echo "../desc-apartament.php?id=".$rowe['id'];
}
echo "' title='Go to ads page'><img src='images/info.jpg' alt='Info ads'/><span>Go to ads page</span></a>";
}
echo'
</li>
</ul>
</div>
</div>
</div>
<div id="footer">';
include 'footer.php'; echo'
</div>
';
}[/embed]