Click here to Skip to main content
15,885,546 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more: , +
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
<?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";

}
?>


HTML
<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
<?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
<html>
<head>
<title>Image Upload</title>
<style>
body {font-family:Verdana, Geneva, sans-serif;}
</style>
</head>

<body>
<?php
//error handler function
function catchError($errno, $errmsg, $a, $b, $c)
{
echo "<b>Error:</b> [$errno] <br />$errmsg<br />";
echo "On Line=".$b;
}

//set error handler
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" />';
}
}
/* 
if($i==2 && isset($_SESSION['img_name_2']))
{
$sel=mysql_query("SELECT * FROM images WHERE image_name='".$_SESSION['img_name_2']."'");
$view = mysql_fetch_array($sel);
$_SESSION['i_2']=$view['image_name'];
echo '<img src="upload/'.$_SESSION['i_2'].'" height="180px" width="220px" />';
}
if($i==3 && isset($_SESSION['img_name_3']))
{
$sel=mysql_query("SELECT * FROM images WHERE image_name='".$_SESSION['img_name_3']."'");
$view = mysql_fetch_array($sel);
$_SESSION['i_3']=$view['image_name'];
echo '<img src="upload/'.$_SESSION['i_3'].'" height="180px" width="220px" />';
}
*/
?>
</div>
<?php
}
?>
</body>
</html>
Posted
Updated 30-May-14 20:53pm
v2
Comments
Nirav Prabtani 31-May-14 3:16am    
Don't post whole code , post only code wherever you have stuck??
C0DE_007 31-May-14 5:13am    
sir it required whole code without it no one will understand what i am doing and what i want to do
C0DE_007 31-May-14 5:14am    
any one plzz help me i am just stuck in uploading the image
C0DE_007 31-May-14 6:41am    
i have make a php program image using passing trough page

like in simple term i have make 2 page in first.html i have put two button
first browse the image
<input type="file" name="file" id="file" >
2- > get the image file name and $_post to second page
<input type="submit">

and in second page sec.php

i have upload image code

where is only submit button so when i click on it .. it will get the image(file) name from first page and then start uploading
but the problem is i am success to passing the image file name to 2 page but the image is not uploading

i am using session ...

and plzz tell where i am doing wrong and what i have to do to make it work thank u

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900