Solved

Trying to build a image upload script. by browsing for file and sending to listmenu. then uploading as arry from listmenu.

Posted on 2003-11-12
4
418 Views
Last Modified: 2011-09-20
Hi all . what im trying to do is have a button on my page that you click it opens a file browser window. you select a file (image) hit the ok button the window closes and inserts the image into a multilined list menu. then you can select another image and add it to the list menu.

then once you have finished you hit the another button on the page (upload)  and it upload the listmenu as an array to the upload script. the upload scripts reads how many files there are in the array and uploads the images to the webserver and inserts the image name into the database.

i know this is asking alot but i havent got a clue how to start it.
any help is appreciated.
0
Comment
Question by:abulink
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
4 Comments
 

Author Comment

by:abulink
ID: 9736835
i want to do what this does but not in java. i want to use php and javascript.

http://www.haller-systemservice.net/jupload/demo/
0
 
LVL 13

Accepted Solution

by:
lozloz earned 250 total points
ID: 9737389
hi,

here's how you would do it:

at the very top of the page, you need session_start();. for your form, you need just a file upload box (input type="file" name="fileupload"), and have the form with action="<? print $_SERVER["PHP_SELF"]; ?>". above this html, you'll want to do the processing. to detect a file being uploaded, you can use if($_FILES["file"]["name"]) {. then you need to copy the file to your images folder, so copy($_FILES["file"]["tmp_name"], "../images/" . $_FILES["file"]["name"]); or something. after this you should add the name of the file to an array of files in your session. $_SESSION["uploaded"][] = $_FILES["file"]["name"];. if you wanted to display the images currently uploaded, you could put <ul> around a foreach($_SESSION["uploaded"] as $val) { clause and have print "<li><img src=\"/images/$val\" alt=\"$val\"></li>\n"; inside it. your form should have two buttons, one being upload and one being finish.. so above your form, you need an elseif clause for the the if($_FILES["file"]["name"] { part.. this will deal with the files listed in $_SESSION["uploaded"] by adding entries to the db. within this clause you would have foreach($_SESSION["uploaded"] as $key => $value) {
  $query = "INSERT INTO table (name) VALUES ('" . $value . "')";
  $result = mysql_query($query) or die(mysql_error() . $query);
  $_SESSION["uploaded"][$key] = "";
}

that's probably really hard to follow.. here's a break down of how the script should look

<?
session_start();
if($_FILES["file"]["name"]) {
  # use copy() to upload the image to the correct directory
  # store the name in the session array
} elseif($_POST["checkout"]) {
  # loop through each item in the session array variable you have for uploaded files and execute a query to add them to the database
  # unset the appropriate session variable so it won't be added again
}
# print list of currently uploaded images if you want
print "<ul>\n";
foreach($_SESSION["uploaded"] as $val) {
  print "<li><img src=\"/images/$val\" alt=\"$val\"></li>\n";
}
print "</ul>\n<br />";  
# output your form
?>
<form action="<? print $_SERVER["PHP_SELF"]; ?>" method="POST">
File: <input type="file" name="fileupload" size="40"><br /><br />
Add file: <input type="submit" name="addfile" value="Add file"> | Complete uploads: <input type="submit" name="checkout" value="Checkout">
</form>

hope it helps

loz
0

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Foreword (July, 2015) Since I first wrote this article, years ago, a great many more people have begun using the internet.  They are coming online from every part of the globe, learning, reading, shopping and spending money at an ever-increasing ra…
Part of the Global Positioning System A geocode (https://developers.google.com/maps/documentation/geocoding/) is the major subset of a GPS coordinate (http://en.wikipedia.org/wiki/Global_Positioning_System), the other parts being the altitude and t…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
The viewer will learn how to count occurrences of each item in an array.

739 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question