I need to write code that looks for files ending in .jpg in an uploads directory, and adds them as images to the page. I'm not too sure how to go about doing this.

I've done the form that allows someone to choose a file to upload:

<form method="post" action="image.php" enctype="multipart/form-data">
    <label for="file">Filename:</label>
    <input type="file" name="file" id="file">
    <br />
    <input type="submit" name="submit" value="Submit">
</form>

I'm also not too sure how to write a PHP script to process the request from the form. I need it to check thath the upload is a valid image, and move it into an appropriate place if it is.

Recommended Answers

All 6 Replies

Thanks, that was quite helpful. But I'm not sure how to display the images like a gallery on a page once it has been uploaded.

Member Avatar for LastMitch

@TheHealer

Thanks, that was quite helpful. But I'm not sure how to display the images like a gallery on a page once it has been uploaded.

I'm not sure what you are asking? You mean want to display the image from that folder?

For example, you upload the image to this folder called images

This is how you link the image (the file is 01.jpg) :

<img src="images/01.jpg" width="" height="" alt="" />

Is this what you are asking>?

Yeah, that's right. I wanted to move the uploaded images into a separate folder and then display the images in this folder onto a page dynamically.

I managed to do it like this:

foreach (glob("/path/*.jpg") as $filename) {
    echo "<img src=" . $filename . ">";
}

It worked. Thanks for your help @LastMitch

Member Avatar for LastMitch

@TheHealer

It's good you find the answer!

If your question has been answer just click "Mark Solved" Thanks!

@LastMitch

Oh true. Thanks heaps for your help.

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.