Shiyloh Fisher Shiyloh Fisher - 4 years ago 69
PHP Question

How to upload photo and display in folder and page using php?

I'm trying to make where you can upload a photo and show in folder. Then when you go to the page it will show you All photo's that were uploaded. I'm using PHP and HTML for this project.
Hopefully You understand my project by now.

This is my php code


echo "Success";
<link rel="stylesheet" type="text/css" href="css/main1.css"/>
<?php include("includes/navigation.php"); ?>
<form action="" method="POST" enctype="multipart/form-data">
<input type="file" name="image" />
<input type="submit"/>


To show on page:

$dirname = "uploads/";
$images = glob($dirname."*.*");

foreach($images as $image) {
echo '<img src="'.$image.'" /><br /><br />';

Help will be appreciated. Thanks,

Answer Source
$dir = './';
$name = $_FILES['image']['name'];
$fullpath = $dir.$name;
$extension = pathinfo($name, PATHINFO_EXTENSION);
$tmpFilename = pathinfo($name, PATHINFO_FILENAME);
$i = 1;

    $_FILES['image']['name'] = $tmpFilename.'('.$i.')'.$extension;
    $fullpath = $dir.$_FILES['image']['name'];
    move_uploaded_file($_FILES('image']['tmp_name'], $fullpath);

In your form action attribute put:


Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download