0

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.

2
Contributors
6
Replies
7
Views
5 Years
Discussion Span
Last Post by TheHealer
0

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.

0

@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>?

0

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

0

@TheHealer

It's good you find the answer!

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

Edited by LastMitch: grammer

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.