BR
asked on
uploading multiple image with php
I need to let my users to upload multiple images to my web site,
do you have the code for uploading multiple image with php?
I don't show error messages on my page for the security risk, they are off by default.
do you have the code for uploading multiple image with php?
I don't show error messages on my page for the security risk, they are off by default.
ASKER
Dear Julian,
thank you, As you guest, I prefer the first approach.
Do you have complete code or sample for this?
I need to let my users upload only jpeg and .gif files and I need to limit the file size.
do you have complete code for this?
thank you, As you guest, I prefer the first approach.
Do you have complete code or sample for this?
I need to let my users upload only jpeg and .gif files and I need to limit the file size.
do you have complete code for this?
ASKER
Let me try it please.
I will let you know after i try it. Thank you
I will let you know after i try it. Thank you
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
This is my teaching example showing how to use HTML5 to send a multiple-file upload to your server.
<?php // demo/upload_multiple_html5_example.php
/**
* This script demonstrates the HTML5 document that you need to use
* for multiple file uploads. The "action=" script would be in a
* separate document.
*/
error_reporting(E_ALL);
/**
* Activate these lines to see the request variables
*
var_dump($_POST);
var_dump($_FILES);
*
*/
// CREATE OUR WEB PAGE IN HTML5 FORMAT
$htm = <<<HTML5
<!DOCTYPE html>
<html dir="ltr" lang="en-US">
<head>
<meta charset="utf-8" />
<meta name="robots" content="noindex, nofollow" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<style type="text/css">
/* STYLE SHEET HERE */
</style>
<script src="https://code.jquery.com/jquery-latest.min.js"></script>
<script>
$(document).ready(function(){
/* JQUERY CODE HERE */
});
</script>
<title>HTML5 Page With jQuery in UTF-8 Encoding</title>
</head>
<body>
<noscript>Your browsing experience will be much better with JavaScript enabled!</noscript>
<form enctype="multipart/form-data" method="post">
<input type="file" multiple name="my_files[]" />
<input type="submit" />
</form>
</body>
</html>
HTML5;
// RENDER THE WEB PAGE
echo $htm;
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Dear Ray,
thank you very very much.
Dear Julian Hansen, I thank you too. Somehow, I couldn't upload files with your code. I'm sure it's my fault.
But Ray's code works, perfectly fine.
thank you very very much.
Dear Julian Hansen, I thank you too. Somehow, I couldn't upload files with your code. I'm sure it's my fault.
But Ray's code works, perfectly fine.
ASKER
Dear Ray Paseur,
I use your code, I can see what I uploaded on the page.
echo '<br/>See the file: <a target="_blank" href="' . $my_file_url . '">' . $my_file_url . '</a><br/>' . PHP_EOL;
Since it's more than one picture, how can I insert the link into my database?
I think I can insert the link into database inside the foreach loop that you use to print out the link on the page.
if I do this, would it work inside the foreach loop?
$sql = "INSERT INTO ilan (uid,imageurl) VALUES ('$uid','$my_file_url');"
but there is more than one image url? How can I do this?
Normally I insert all the data in one row whit where clause. ( Where uid='$uid'; )
Should I create a lookup table to insert the picture urls?
I use your code, I can see what I uploaded on the page.
echo '<br/>See the file: <a target="_blank" href="' . $my_file_url . '">' . $my_file_url . '</a><br/>' . PHP_EOL;
Since it's more than one picture, how can I insert the link into my database?
I think I can insert the link into database inside the foreach loop that you use to print out the link on the page.
if I do this, would it work inside the foreach loop?
$sql = "INSERT INTO ilan (uid,imageurl) VALUES ('$uid','$my_file_url');"
but there is more than one image url? How can I do this?
Normally I insert all the data in one row whit where clause. ( Where uid='$uid'; )
Should I create a lookup table to insert the picture urls?
Did you try this link http://www.marcorpsa.com/ee/t1883.php
ASKER
Dear Julian,
Yes, I tried. Unfortunately, I couldn't make it work
Yes, I tried. Unfortunately, I couldn't make it work
Just checking in this post you said
Ray's solution uses a single input with the multiple attribute - which was the second approach I suggested.
Which one are you wanting to use the first (individual inputs) or the second (single input with multiple attribute)?
thank you, As you guest, I prefer the first approach.
Ray's solution uses a single input with the multiple attribute - which was the second approach I suggested.
Which one are you wanting to use the first (individual inputs) or the second (single input with multiple attribute)?
ASKER
Dear Julian,
I somehow manage it. Ray's code is working and I do not have deep knowledge about programming. I'm sure yours is working too.
I will use Ray's code for now. But I have to work on it.
I inserted the link of the pictures to my database, so that everything seems fine now. I will split the points.
I somehow manage it. Ray's code is working and I do not have deep knowledge about programming. I'm sure yours is working too.
I will use Ray's code for now. But I have to work on it.
I inserted the link of the pictures to my database, so that everything seems fine now. I will split the points.
ASKER
thank you both.
Assuming you are uploading your files with standard HTML file inputs there are two approaches
Approach 1 - you name each file input
Open in new window
This will result in a $_FILES array that looks like thisOpen in new window
Approach 2 - use the multiple attribute on the <input> control. This allows you to select multiple files and assign them to a single <input>Open in new window
This will result in a $_FILES array that looks like thisOpen in new window
Use the first approach when you want to request specific images for a specific purpose - the named inputs allows you to map the image to its purpose.
The second approach is if you are providing something like a gallery - there can be any number of images in any order.
Assuming you go with Approach 1. Then you would need PHP code that processes the first $_FILES array
Open in new window