i want to display the image by passing many page ... i am success passing the variable name (image name) but how to attach the session file name with my uploading function it will upload only session file only
... plzz help me guyzz
here are my codes
1-> page here user will browse the file from computer and i added paypal button so after clicking paypal buy now button
index.php // Main page *Browse image * form computer
<?php
session_start();
if (isset($_POST['file'])){
$file_name = $_POST['file'];
$_SESSION['file'] = $file_name;
echo "<form action=\"pay.php\" method=\"post\">\n";
echo " <input type=\"hidden\" name=\"cmd\" value=\"_s-xclick\">\n";
echo " <input type=\"hidden\" name=\"hosted_button_id\" value=\"XXX\">\n";
echo " <input type=\"image\" src=\"https://www.paypalobjects.com/en_US/i/btn/btn_buynowCC_LG.gif\" border=\"0\" name=\"submit\" alt=\"PayPal - The safer, easier way to pay online!\">\n";
echo " <img alt=\"\" border=\"0\" src=\"https://www.paypalobjects.com/en_US/i/scr/pixel.gif\" width=\"1\" height=\"1\"></form>\n";
}
?>
<form action="" method="post">
<input type="file" name="file" id="file" >
<br>
<input type="submit">
</form>
2-> so user will receive this page
pay.php // payment complete
<?php
echo "thank you we have received your payment <br> Please Follow this link to upload your file<br> <a href='image_upload.php'>Link</a>";
?>
3-> main page now user want to upload the image and display it but how upload that image which is selected in first page so i am success to getting the file name .. but not getting how to attach that file name with my upload function code ...
image_upload.php // Now upload your photo // but when i click on submit button the session image is not uploading in diectory and not displaying
<html>
<head>
<title>Image Upload</title>
<style>
body {font-family:Verdana, Geneva, sans-serif;}
</style>
</head>
<body>
<?php
function catchError($errno, $errmsg, $a, $b, $c)
{
echo "<b>Error:</b> [$errno] <br />$errmsg<br />";
echo "On Line=".$b;
}
set_error_handler("catchError");
require ('database.php');
session_start();
$img_name =$_SESSION['file'];
echo "downoload your file <br> <a href=".$img_name.">".$img_name."</a> <br> or buy another file from here <a href='index.php'> Buy Another file </a>";
?>
<div style="position:fixed; right:5px; top:5px">
<form method="post"><input type="submit" name="ds_btn" value="Destroy Session" /></form>
</div>
<?php
if(isset($_REQUEST['ds_btn']))
{
unset($_SESSION['img_name_1']);
unset($_SESSION['img_name_2']);
unset($_SESSION['img_name_3']);
session_destroy();
}
if(isset($_POST['submit']) && isset($_POST['hdn']))
{
if(isset($_POST['hdn']))
{
for($j=1;$j<=3;$j++)
{
if($_POST['hdn']==$j)
$_SESSION['img_name_'.$j]= $_FILES['file']['name'];
}
}
$img_name= $_FILES['file']['name'];
$img_type= $_FILES['file']['type'];
$img_size= $_FILES['file']['size'];
$img_tmp_path= $_FILES['file']['tmp_name'];
$img_error= $_FILES['file']['error'];
$allowedExts = array("gif", "jpeg", "jpg", "png");
$temp = explode(".", $img_name);
$extension = end($temp);
if ( ( ($img_type == "image/gif")
|| ($img_type == "image/jpeg")
|| ($img_type == "image/jpg")
|| ($img_type == "image/pjpeg")
|| ($img_type == "image/x-png")
|| ($img_type == "image/png"))
&& ($img_size < 2000000)
&& in_array($extension, $allowedExts))
{
if ($img_error > 0)
{
echo "Return Code: " . $img_error . "<br>";
}
else
{
if (file_exists("upload/".$img_name))
{
echo $img_name . " already exists. <br /><br />";
}
else
{
move_uploaded_file($img_tmp_path,"upload/".$img_name);
echo "Stored in: " . "upload/".$img_name."<br /><br />";
$updt=mysql_query("INSERT INTO images (image_name) VALUES('".$_FILES['file']['name']."')");
if($updt)
echo 'Image name stored in database successfully.'."<br />";
else
echo 'Error in updating image name in database. Error:'.mysql_error()."<br />";
}
}
}
else
{
echo "Invalid file";
}
}
for($i=1;$i<=3;$i++)
{
?>
<div style="border:1px solid black; width:220px; height:260px;; padding:5px; margin:10px; float:left">
<form method="POST" enctype="multipart/form-data">
<table>
<tr>
<td><input type="file" name="file" id="file"><br></td>
<td><input type="hidden" name="hdn" value="<?php echo $i; ?>" /></td>
</tr>
<tr>
<td><input type="submit" name="submit" value="Submit"></td>
</tr>
</table>
</form>
<?php
for($k=1;$k<=5;$k++)
{
if($i==$k && isset($_SESSION['img_name_'.$k]))
{
$sel=mysql_query("SELECT * FROM images WHERE image_name='".$_SESSION['img_name_'.$k]."'");
$view = mysql_fetch_array($sel);
$_SESSION['i_'.$k]=$view['image_name'];
echo '<img src="upload/'.$_SESSION['i_'.$k].'" height="180px" width="220px" />';
}
}
?>
</div>
<?php
}
?>
</body>
</html>