in img2.php
<form action="img3.php" method="post" enctype="multipart/form-data"
name="uploadImage" id="uploadImage">
<p>
  <input type="hidden" name="MAX_FILE_SIZE" 
    value="<?php echo MAX_FILE_SIZE; ?>" />
  <label for="image">Upload image:</label>
  <input type="file" name="image" id="image" />
</p>
<input type="hidden" name="MAX_FILE_SIZE" 
    value="<?php echo MAX_FILE_SIZE; ?>" />
  <label for="image">Upload image:</label>
  <input type="file" name="photo" id="image" />
</p>

<p>
  <input type="submit" name="upload" id="upload" 
value="Upload" />
</p>
</form>

in img3.php
the code was lyk this:::
<?php
$photo = file_get_contents($_FILES['image']['tmp_name']);
header('Content-Type: image/jpeg');
echo $photo ;

$photo2 = file_get_contents($_FILES['photo']['tmp_name']);
header('Content-Type: image/jpeg');
echo $photo2 ;

?>
but it was dispalying 1st image only.

help me

Hi,

Based on your script above, you should only get 1 image at a time.. The reason is that you are acessing the image file from your PHP tmp directory.

What you need to do is use

$new_location = 'yourDir/filename.extension';
move_uploaded_file($_FILES['image']['tmp_name'], $new_location);

## then you can bring it on the screen

echo '<img src="$new_location" />';

If you want to upload multiple-images, then you will have to add more file input. If you want to view all the images in the directory including the newly uploaded file, then you will need to write another php script for that..e.g. scan image directory and then iterate through its contents based on the extension you want to show..

will help me a lot

this coding..is also use for....image declaretion

Thank u veedeoo.but My requirement is I want to display the images in img3.php.
In img3.php i have 2 place submit button again when ever user clicks the submit button at that time i want to move my images to my images directory.

hello veedeoo..as based on ur suggestion i move my files to the image directory.and also i save the images in datatbase.after inserting the image into database i want to delete those images in images directory.can u please suggest a piece of code for deleting the images in dynamically

for deleting image from db you have to first check for the id of image means what image you want to delete pass that image id in a link and fire a delete query on delete.php page.first you have to display all images on page like say display_all_image.php
give a link on every image for example

<a href="delete.php?id=<?php $row[id]; ?>">delete</a>

after clicking on that link you redirect to the delete.php page on witch you have to code something like that

<?php 
if(isset($_GET['id']))
{
    $id=$_GET['id'];
}

$delete="delete from youttablename where `image_id`='$id'";
$result=mysql_query($delete);
if(!$result)
{
    die(mysql_error());
}

?>

Hi,

Do as suggested by arti18, and then you go like this just right after the delete query..

WARNING! make sure the page reponsible for deleting items both database entries and images in the directory, must have a controlled access. Otherwise, if the search spider is able to crawl these images and accidentally followed the delete link, all of your images will be gone in one sweep...

first we check if the file exist.. let say the file name you have in the directory is based on the image_id.ext, and it is located in the imagedirectory.. we can do like this

## the delete query here..
## put the mysql error here.
## check if the file exist
    ## define the location of the image to be deleted
    $image_file = 'YourImageDirectory/'.$image_id.'.jpg;

 if (file_exists($image_file)) {
    unlink($image_file);
    echo 'image deleted';
} 
else {

    echo 'image does not exist';
}

Alternatively, we can write a simple class for the upload processor, and then just add the methods for database insert and delete..

commented: Dude, I joined as you suggested.. :) +0

Thank You all

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.