?
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
Medium Priority
?
420 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 1000 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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

This article discusses how to create an extensible mechanism for linked drop downs.
There are times when I have encountered the need to decompress a response from a PHP request. This is how it's done, but you must have control of the request and you can set the Accept-Encoding header.
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.
Suggested Courses

752 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