PHP File Upload: Syntax? [closed] - php

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 8 years ago.
Improve this question
I am currently creating a system where a user can upload both information a corresponding picture to a db. However, when I call the move_upload_file() function, it is not liking my syntax when specifying the new destination.
The line of code I am referring to looks like this:
if(move_uploaded_file($_FILES['upload']['tmp_name'], "images/{$_FILES['upload']['name']")){
And the error I'm getting is
Parse error: syntax error, unexpected '")){'
(T_CONSTANT_ENCAPSED_STRING), expecting '}' in
/Applications/XAMPP/xamppfiles/htdocs/serverside/phptut/addbyform.php
on line 27
I am also using Sublime Text 2 and ['upload'] highlights in bright pink.
For further context this is my entire script thus far:
<?php
printForm();
//when "submit" tie together values and variables
if($_POST['submit']=="Submit"){
$email = cleanData($_POST['email']);
$first = cleanData($_POST['first']);
$last = cleanData($_POST['last']);
$status = cleanData($_POST['status']);
//$image = cleanData($_POST['image']);
//echo "Data cleaned";
addData($email, $first, $last, $status);
}
else{
//printForm();
}
function checkUpload(){
//check for uploaded files
if(isset($_FILES['upload'])){ //upload refers to form element "upload"
$allowed = array ('image/pjpeg', 'image/jpeg', 'image/JPG', 'image/X-PNG', 'image/PNG', 'image/png', 'image/GIF');
if(in_array($_FILES['upload']['type'], $allowed)){//if upload if in the allowed file types
echo "uploading files...";
//move the file over
if(move_uploaded_file($_FILES['upload']['tmp_name'], "images/{$_FILES['upload']['name']")){
//moveuf method moves to tmp folder then moves to final location
echo "<p>The file has been uploaded 'dude'</p>";
$image="{$_FILES['upload']['name']}";
print "$image";
}//end of moving DAT IMG :3
else{
echo '<p>Please upload a JPEG, GIF or PNG image.<p>';
if($FILES['upload']['error'] > 0){
}
}
}
}
}
//cleans information
function cleanData($data){
if(!$status){ //everything except for status take out spaces
$data = trim($data);
}
$data = stripslashes($data);//no slashes
$data = htmlspecialchars($data);//no special characters
$data = strip_tags($data);//no html tags
return $data;
}
//inserts data into db
function addData($email, $first, $last, $status){
//echo "Ready to add data";
include("dbinfo.php");//access db
$image = checkUpload();
$sql = "INSERT INTO contacts VALUES(null, '$email', '$first', '$last', '$status', '$image')";
//null because of ID aka primary key automatically incremented:3
$result = mysql_query($sql) or die(mysql_error());
//takes sql arugment for query OR if it can't you get a BUMMER DUDE
echo <<<HERE
<b>The following has been added:</b>
<ul>
<li>E-mail: $email</li>
<li>First: $first</li>
<li>Last: $last</li>
<li>Status: $status</li>
<li>Image File:<br/> <img src="images/$image" /></li>
</ul>
HERE;
}
function printForm(){
$pageTitle ="Add a Contact";
include("header.php");
echo <<<EOD
<b>Add a Contact</b>
<form method = "POST" enctype="multipart/form-data">
<div>
<label for="email">Email*:</label>
<input type="text" name="email" id="email" required="required">
</div>
<div>
<label for="first">First Name*:</label>
<input type="text" name="first" id="first" required="required">
</div>
<div>
<label for="last">Last Name*:</label>
<input type="text" name="last" id="last" required="required">
</div>
<div>
<label for="status">Status*:</label>
<input type="text" name="status" id="status" required="required">
</div>
<div>
<label for="image">Image*:</label>
<input type="file" name="upload" size="30" id="upload" required="required"><br/>
<small>Must be less than 512kb. Only JPG, GIF, and PNG files</small>
</div>
<div id="mySubmit">
<input type="submit" name="submit" value="Submit">
</div>
</form>
EOD;
}
include("footer.php");
?>
Would anyone be able to let me know what I am doing wrong?
Thanks.

You missed one bracket !
if(move_uploaded_file($_FILES['upload']['tmp_name'], "images/{$_FILES['upload']['name']}")){
The one after ['name'] ...

Related

$_FILES name not uploading to database correctly [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Closed 5 years ago.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Improve this question
So I have a simple image uploading website I'm creating for a little project. It's all working just great, except for the file path column in the database.
For some reason it will sometimes include the variables i'm telling it to, and sometimes not.
$user = $_SESSION['user'];
//file properties
$fileName = $_FILES["uploadedImage"]["name"];
$fileType = $_FILES["uploadedImage"]["type"];
$fileSize = $_FILES["uploadedImage"]["size"];
$fileTempName = $_FILES["uploadedImage"]["tmp_name"];
$error = $_FILES["uploadedImage"]["error"];
$random = substr(md5(microtime()),rand(0,26),16); //create random characters to avoid name duplication.
$path = "uploads/" . $_SESSION['userName'] . $random . $fileName;
The path always contains "uploads/" but only sometimes would contain the session user name, random, and only rarely the filename, even on the same files. I'm echoing out these variables before I submit the form, and they are all correct before submitting the form and uploading to the database. All other columns are correctly filled when I submit the form.
if ( isset( $_POST['formSubmit'] )) {
//prevent SQL injections and invalid inputs
$title = trim($_POST['title']);
$title = strip_tags($title);
$title = htmlspecialchars($title);
$title = mysqli_real_escape_string($db, $title);
$description = trim($_POST['description']);
$description = strip_tags($description);
$description = htmlspecialchars($description);
$description = mysqli_real_escape_string($db, $description);
if (empty($title) || strlen($title) < 1) {
$titleError = "Title required.";
$formError = true;
}
if ($formError) {
$errorMessage = "Please fill out the upload form properly.";
} else {
$query = mysqli_query($db, "INSERT INTO IMAGE(imageID,userID,title,description,path)
VALUES('','$user','$title','$description','$path')");
Here's the form itself:
<form method="POST" action="<?php $_SERVER['PHP_SELF'] ?>">
<div class="row">
<div class="col-sm-12">
<span class="errorText"><?php echo $errorMessage; ?></span>
<br><br>
</div>
</div>
<div class="row">
<div class='col-sm-1'><!--spacer--></div>
<div class="col-sm-2">
<label for="title">Title:</label>
</div>
<div class="col-sm-6">
<input type="text" id="title" name="title" placeholder="Enter your image title here..." >
</div>
<div class="col-sm-2"><span class="errorText"><?php echo $titleError; ?></span></div>
<div class='col-sm-1'><!--spacer--></div>
</div>
<br>
<div class="row">
<div class='col-sm-1'><!--spacer--></div>
<div class="col-sm-2">
<label for="description">Description:</label>
</div>
<div class="col-sm-6">
<input type="text" id="description" name="description" placeholder="Describe your image here...">
</div>
<div class="col-sm-2"><span class="errorText"><?php echo $descriptionError; ?></span></div>
<div class='col-sm-1'><!--spacer--></div>
</div>
<br>
<br>
<input type="submit" value="Submit" name = "formSubmit" id="formSubmit" class="btn">
<br>
<br>
</form>
The form is missing enctype="multipart/form-data" attribute.
<form method="POST" enctype="multipart/form-data">
Also, even if this is unrelated to the question, I strongly recommend you to use MySQLi prepared statement. It help you avoid SQL injection without the need to manually escaping parameters.

How to upload multiple images url into database and move files to folder [duplicate]

This question already has answers here:
Multiple file upload in php
(14 answers)
Closed 6 years ago.
i want to upload multiple images url into database , after which i will move the file to an upload folder, then want to display the images and possibly edit by changing or removing them. i've been able to do that with one, but want to do that for multiple pics.
this is my html
<section class="form-group">
<section class="col-md-12">
<label for="price">Add Image</label>
<input type="file" name="uploadedfile" id="uploadedfile" class="form-control" />
<input type="hidden" name="MAX_FILE_SIZE" value="100000">
</section>
</section>
Now my php script
$target_path="uploads/";
$target_path=$target_path.basename($_FILES['uploadedfile']['name']);
if(move_uploaded_file($_FILES['uploadedfile']['tmp_name'], $target_path)) {
}
if($target_path==="uploads/"){
$target_path="images/no-thumb.png";
}
$query="insert into properties
(owner,email,contact,title,location,price,description,property_id,property_type,bedrooms,images,gsize,size,status,post_date)
values('$name','$email','$contact',
'$title','$location','$price','$description','$listid',$type','$bedroom','$target_path','$gsize','$size','$status',now())";
$result=mysqli_query($dbc,$query);
if($result){
echo '<p class="bg-success alert alert-success text-center">Property Listing Successful</p>';
}else{
echo '<p class="bg-danger alert alert-danger">My bad!!! Something went totally wrong. Try again later while i try to fix it <span class="close pull-right"> <span class="close pull-right"> <a href="#" >× </a></span></p>';
}
```
Change input field to
<input type="file" multiple="true" name="uploadedfile[]" id="uploadedfile" class="form-control" />
Or
<input type="file" multiple="multiple" name="uploadedfile[]" id="uploadedfile" class="form-control" />
You will get array of selected images in $_FILES. You can loop through it and save it one by one.
Here is what you need to do:
1.Input name must be be defined as an array i.e. name="inputName[]"
2.Input element must have multiple="multiple" or just multiple
3.In your PHP file use the syntax "$_FILES['inputName']['param'][index]"
4.Make sure to look for empty file names and paths, the array might contain empty strings
HTML:
input name="upload[]" type="file" multiple="multiple" />
PHP :
// Count # of uploaded files in array
$total = count($_FILES['upload']['name']);
// Loop through each file
for($i=0; $i<$total; $i++) {
//Get the temp file path
$tmpFilePath = $_FILES['upload']['tmp_name'][$i];
//Make sure we have a filepath
if ($tmpFilePath != ""){
//Setup our new file path
$newFilePath = "./uploadFiles/" . $_FILES['upload']['name'][$i];
//Upload the file into the temp dir
if(move_uploaded_file($tmpFilePath, $newFilePath)) {
//Handle other code here
}
}
}
source

Multiple image upload and write to database

I've managed to get a photo to be uploaded to the server and then written to the database thanks to quite a bit of help but I need to be able to upload three files and each needs to be written to the database accordingly. So at the moment only photo1 is being uploaded and written, I'd like to create another form input for photo2 and 3 and have them also written and uploaded. Sorry I'm almost a complete beginner with php, any help will be hugely appreciated! thanks in advance.
<?php
session_start();
include_once('../php/connection.php');
if (isset($_SESSION['logged_in'])) {
if (isset($_POST['title'], $_POST['content'], $_FILES['photo1'])) {
$title = $_POST['title'];
$content = nl2br($_POST['content']);
$name = $_FILES['photo1']['name'];
$tmp_name = $_FILES['photo1,']['tmp_name'];
$target = '../lifestyle/'.$name;
if (move_uploaded_file($tmp_name, $target)) {
$stmt = $pdo->prepare('INSERT INTO article (article_title, article_content, photo_1, photo_2) VALUES (?,?,?,?)');
$stmt->execute(array($title,$content,$name,));
header('Location: index.php');
exit();
}
}
?>
<form action="add.php" method="post" autocomplete="off" enctype="multipart/form-data"/>
<<input type="text" name="title" id="title"/>
<textarea name="content"></textarea></dt>
<input type="file" name="photo1" >
<input type="submit" id="add article"/>
</form>
Use attribute multiple and make some sort of array of the name:
<input type="file" name="photo[]" multiple >
OR
<input type="file" name="photo[]">
<input type="file" name="photo[]">
<input type="file" name="photo[]">
http://php.net/manual/en/features.file-upload.multiple.php

PHP File Upload returning extensions false

I have a form which is meant to upload articles to my database within this form I have a file upload field the objectives of my file upload is as follows:
Limit file extensions to image format
Rename file to something random
Create a new directory based on the ID of the entry into the database
Keep the extension of the file that is uploaded
Every time I hit the submit button the form seems to think I have tried to upload a file that isn't in the list of allowed extensions, it prints this error (the fields however are uploaded to the database):
wrong files format , allowed only "Array"
I'm not quite sure why this is the case as I know I'm inputting the correct file format.
public function insert ($field) {
if ($stmt = $this->mysqli->prepare("INSERT INTO articles (title, story, storyb, storyc, author, date_created, section, youtubeid) VALUES (?, ?, ?, ?, ?, ?, ?, ?)")) {
/* Set our params */
$title = isset($_POST['title']) ? $this->mysqli->real_escape_string($_POST['title']) : '';
$story = isset($_POST['story']) ? $this->mysqli->real_escape_string($_POST['story']) : '';
$storyb = isset($_POST['storyb']) ? $this->mysqli->real_escape_string($_POST['storyb']) : '';
$storyc = isset($_POST['storyc']) ? $this->mysqli->real_escape_string($_POST['storyc']) : '';
$author = isset($_POST['author']) ? $this->mysqli->real_escape_string($_POST['author']) : '';
$date_created = isset($_POST['date_created']) ? $this->mysqli->real_escape_string($_POST['date_created']) : '';
$section = isset($_POST['section']) ? $this->mysqli->real_escape_string($_POST['section']) : '';
$youtubeid = isset($_POST['youtubeid']) ? $this->mysqli->real_escape_string($_POST['youtubeid']) : '';
/* Bind our params */
$stmt->bind_param('ssssssss', $title, $story, $storyb, $storyc, $author, $date_created, $section, $youtubeid);
/* Execute the prepared Statement */
$stmt->execute();
/* Echo results */
echo "Inserted {$title} into database\n";
/* Close the statement */
$stmt->close();
}
else {
/* Error */
printf("Prepared Statement Error: %s\n", $mysqli->error);
}
// Handling file upload
$extensions = array(".jpg",".jpeg",".gif",".png", ".JPG", ".JPEG", ".PNG", ".GIF");
$extension = strrchr($_FILES['uploadImage']['name'], '.');
$path = "../files/uploads/articles_gallery/" . $this->mysqli->insert_id;
$filename = uniqid(rand(), true);
if (!in_array($extension, $extensions))
{
echo'<center>wrong files format , allowed only <strong>"'.$extensions.'"</strong></center>';
} else {
if (!is_dir($path))
{
die('Error: ' . $mysqli->error());
}
echo "<h3>1 record added</h3>";
mkdir($path, 0777);
move_uploaded_file($_FILES['uploadImage']['tmp_name'], $path, $filename);
} // File Upload End
}
Insert.php
<div id="form">
<form action="insert.php" method="post" name="insert" id="articleform">
<input type="input" name="title" id="title" class="detail" id="title"/>
<textarea name="story" id="story" class="detail" placeholder="Insert article here"></textarea>
<input id="uploadImage" type="file" name="uploadImage" onchange="PreviewImage();" class="" />
<img id="uploadPreview" style="width: 250px; height: 200px;" />
<textarea name="storyb" id="storyb" class="detail" spellcheck="true" placeholder="Insert article here"></textarea>
<textarea name="storyc" id="storyc" class="detail" spellcheck="true" placeholder="Insert article here"></textarea>
<input type="input" name="author" id="author" class="detail"/>
<? $today = date("l j M Y"); // Monday 13 April 2013 ?>
<input type="hidden" name="date_created" id="date_created" class="detail" value="<? echo $today;?>" />
<input type="hidden" name="section" id="section" class="detail" value="game"/>
<input type="input" name="youtubeid" class="detail" id="youtubeid" />
<input type="submit" id="submit" name="submit" value="Submit Article " />
</form>
strchr() will give you true/false if the character (in your case, ".") exists in the string. So to get the file extension, you could use something like:
$extension = end(explode('.', $filename));
.. But maybe a function like pathinfo() could be usefull in this case too.
Furthermore, in your error message you use $extensions. This is a var with type "array", and thus the string representation is "Array". I think you meant $extension (without the S) there. Or, maybe, you want to list all correct extensions this way: implode(',', $extensions).
Note that checking on extensions is not a safe way to check what kind of content is present. I can easily upload a .exe, by just renaming it to .jpg.
Oh, and chmod-ing a directory/file to mode 777 is highly discouraged due to security reasons.
if you want to display the available extension you can't just concat your array with your message. you have to iterate all values.
The code to get extension is wrong.
$extension = strrchr($_FILES['uploadImage']['name'], '.');
change it to
$extension = strtolower(substr($_FILES['uploadImage']['name'],-3,3));
if extension is 3 characters long or explode()
and get the last parametr. This is not good way anyway, I prefer to check MIME type
$extension = strtolower(end(explode('.', $_FILES['uploadImage']['name'])));
change your extension array to
$extensions = array("jpg","jpeg","gif","png");
also add to your form
enctype="multipart/form-data"
your error message is wrong because you want to echo array instead of string use implode() to join array
implode(";",$extensions)
update your form from:
<form action="insert.php" method="post" name="insert" id="articleform">
To :
<form action="insert.php" method="post" name="insert" id="articleform" enctype="multipart/form-data">

Modal Pop Up To Hover Over Parent Page [closed]

It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.
Closed 11 years ago.
I wonder whether someone could help me please.
I've really got myself in a bit of a pickle with this and I just seem to be going round in circles to find a solution.
I have created this modal dialog page to allow users to upload images. I would like to access this through the click of the 'Upload Images' button on this page.
The problem I have is two fold, but are linked.
I can't seem to get the modal dialog page to act as a pop dialog hovering over the parent page, instead it opens as another web browser page, and because I'm using two submit buttons, I can't get the 'submit' functionality to work independently i.e. one that submits the form, whilst the other opens up the modal dialog.
I've been working on this for quite some time now, changing the button types, giving specific name to each button and calling that in a Javascript function, but I just can't seem to find the solution.
I just wondered whether someone could perhaps have a look at this please and help me with this problem.
For ease, I've added the code below:
Modal Dialog
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Untitled Document</title>
<link rel="stylesheet" href="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.6/themes/base/jquery-ui.css"
type="text/css" media="all" />
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.4/jquery.min.js" type="text/javascript"></script>
<script src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.6/jquery-ui.min.js" type="text/javascript"></script>
<script type="text/javascript" language="javascript">
$(document).ready(function() {
$("#dialog").dialog();
modal: true
//getter
var modal = $( ".dialog" ).dialog( "option", "modal" );
//setter
$( ".dialog" ).dialog( "option", "modal", true );
});
</script>
</head>
<body style="font-size:62.5%;">
<div id="dialog">
</head>
<?php
//define a maxim size for the uploaded images
//define ("MAX_SIZE","100");
// define the width and height for the thumbnail
// note that theese dimmensions are considered the maximum dimmension and are not fixed,
// because we have to keep the image ratio intact or it will be deformed
define ("WIDTH","150");
define ("HEIGHT","100");
// this is the function that will create the thumbnail image from the uploaded image
// the resize will be done considering the width and height defined, but without deforming the image
function make_thumb($img_name,$filename,$new_w,$new_h)
{
//get image extension.
$ext=getExtension($img_name);
//creates the new image using the appropriate function from gd library
if(!strcmp("jpg",$ext) || !strcmp("jpeg",$ext))
$src_img=imagecreatefromjpeg($img_name);
if(!strcmp("png",$ext))
$src_img=imagecreatefrompng($img_name);
//gets the dimmensions of the image
$old_x=imageSX($src_img);
$old_y=imageSY($src_img);
// next we will calculate the new dimmensions for the thumbnail image
// the next steps will be taken:
// 1. calculate the ratio by dividing the old dimmensions with the new ones
// 2. if the ratio for the width is higher, the width will remain the one define in WIDTH variable
// and the height will be calculated so the image ratio will not change
// 3. otherwise we will use the height ratio for the image
// as a result, only one of the dimmensions will be from the fixed ones
$ratio1=$old_x/$new_w;
$ratio2=$old_y/$new_h;
if($ratio1>$ratio2) {
$thumb_w=$new_w;
$thumb_h=$old_y/$ratio1;
}
else {
$thumb_h=$new_h;
$thumb_w=$old_x/$ratio2;
}
// we create a new image with the new dimmensions
$dst_img=ImageCreateTrueColor($thumb_w,$thumb_h);
// resize the big image to the new created one
imagecopyresampled($dst_img,$src_img,0,0,0,0,$thumb_w,$thumb_h,$old_x,$old_y);
// output the created image to the file. Now we will have the thumbnail into the file named by $filename
if(!strcmp("png",$ext))
imagepng($dst_img,$filename);
else
imagejpeg($dst_img,$filename);
//destroys source and destination images.
imagedestroy($dst_img);
imagedestroy($src_img);
}
// This function reads the extension of the file.
// It is used to determine if the file is an image by checking the extension.
function getExtension($str) {
$i = strrpos($str,".");
if (!$i) { return ""; }
$l = strlen($str) - $i;
$ext = substr($str,$i+1,$l);
return $ext;
}
// This variable is used as a flag. The value is initialized with 0 (meaning no error found)
//and it will be changed to 1 if an error occurs. If the error occures the file will not be uploaded.
$errors=0;
// checks if the form has been submitted
if(isset($_POST['Submit']))
{
$title = ($_POST['title']);
if ($title == '') // if title is not set
$title = '(No Title Provided)';// use (empty title) string
//reads the name of the file the user submitted for uploading
$image=$_FILES['image']['name'];
// if it is not empty
if ($image == '')
{
echo '<b> Error! </b> - You <b> must </b> select a file to upload before selecting the <b> "Upload image" </b> button. Please try again.';
$errors=1;
}
else
if ($image)
{
// get the original name of the file from the clients machine
$filename = stripslashes($_FILES['image']['name']);
// get the extension of the file in a lower case format
$extension = getExtension($filename);
$extension = strtolower($extension);
// if it is not a known extension, we will suppose it is an error, print an error message
//and will not upload the file, otherwise we continue
if (($extension != "jpg") && ($extension != "jpeg") && ($extension != "png"))
{
echo '<b> Error! </b> - The image that you attempted to upload is not in the correct format. The file format <b> must </b> be one of the following: <b> "jpg", "jpeg" </b> or <b> "png" </b>. Please try again.';
$errors=1;
}
else
{
// get the size of the image in bytes
// $_FILES[\'image\'][\'tmp_name\'] is the temporary filename of the file in which the uploaded file was stored on the server
$size=getimagesize($_FILES['image']['tmp_name']);
$sizekb=filesize($_FILES['image']['tmp_name']);
//compare the size with the maxim size we defined and print error if bigger
if ($sizekb > 1150000)
{
echo '<b> Error! </b> - The file that you are attempting to upload is greater than the prescribed <b> 1MB </b> limit. Please try again.';
$errors=1;
}
//we will give an unique name, for example the time in unix time format
$image_name=$title.'.'.$extension;
//the new name will be containing the full path where will be stored (images folder)
$newname="images/".$image_name;
$copied = copy($_FILES['image']['tmp_name'], $newname);
//we verify if the image has been uploaded, and print error instead
if (!$copied)
{
echo '<b> Error! </b> Your file has not been loaded';
$errors=1;
}
else
{
// the new thumbnail image will be placed in images/thumbs/ folder
$thumb_name='images/thumbs/'.$image_name;
// call the function that will create the thumbnail. The function will get as parameters
//the image name, the thumbnail name and the width and height desired for the thumbnail
$thumb=make_thumb($newname,$thumb_name,WIDTH,HEIGHT);
}} }}
//If no errors registred, print the success message and show the thumbnail image created
if(isset($_POST['Submit']) && !$errors)
{
echo '<br><b> Success! </b> - Your image has been uploaded</br>';
echo '<img src="'.$thumb_name.'">';
}
?>
<!-- next comes the form, you must set the enctype to "multipart/form-data" and use an input type "file" -->
<form name="newad" method="post" enctype="multipart/form-data" action="">
<table>
<tr><td><input type="text" name="title" ></td></tr>
<tr><td><input type="file" name="image" ></td></tr>
<tr><td><input name="Submit" type="submit" value="Upload image"></td></tr>
</table>
</form>
</div>
</html>
Parent Page Form Code
<form name="savemyfindstolocation" id="savemyfindstolocation" method="post" action="testdialog.php">
<p><label></label>
</p>
<p align="left">
<input name="userid" type="text" id="userid"/>
<input name="locationid" type="text" id="locationid"/>
<br />
</p>
<div>
<label>
<div align="left">Click on the map to place the marker for the find that has been made and drag until the precise location has been found. </div>
</div>
<p align="left"><label>Find OSGB36 Latitude Co-ordinate<br />
</label>
</p>
<div>
<div align="left">
<input name="findosgb36lat" type="text" id="findosgb36lat" size="20" />
</div>
</div>
<p align="left"><label>Find OSGB36 Longitude Co-ordinate<br />
</label>
</p>
<div>
<div align="left">
<input name="findosgb36lon" type="text" id="findosgb36lon" size="20" />
</div>
</div>
<p align="left"><label>Date of Trip<br />
</label>
</p>
<div>
<div align="left">
<input name="dateoftrip" type="text" id="dateoftrip" size="10" />
</div>
</div>
<p align="left"><label>Find Category</label>
<label><br />
</label>
</p>
<div>
<div align="left">
<?php
mysql_connect("host", "user", "password") or die("Connection Failed");
mysql_select_db("database")or die("Connection Failed");
$query = "SELECT * FROM findcategories";
$result = mysql_query($query);
?>
<select name="findcategory" id="findcategory">
<option value=''>Select a Find Category</option>
<?php
while ($line = mysql_fetch_array($result, MYSQL_ASSOC)) {
?>
<option value="<?php echo $line['findcategory'];?>"> <?php echo $line['findcategory'];?> </option>
<?php
}
?>
</select>
</div>
</div>
<p align="left">Find Name</p>
<div>
<div align="left">
<input name="findname" type="text" id="findname" size="35" />
</div>
</div>
<p align="left"> Find Description</p>
<div>
<div align="left">
<input name="finddescription" type="text" id="finddescription" size="150" />
</div>
</div>
<p align="left">
<label> Detector Used</label>
</p>
<div>
<div align="left">
<select id="detectorname" name="detectorname" onchange="getTextList(this)">
<option value="">Select a Detector</option>
<?php
// QUERY DATABASE TO GET CATEGORIES
$query = mysql_query("SELECT detectorid, detectorname FROM detectors ORDER BY detectorname ASC") or die(mysql_error());
// LOOP THROUGH ROWS RETURNED TO CREATE SELECT BOX
while($row = mysql_fetch_array($query)) {
echo '<option value="'.$row['detectorid'].'">'.$row['detectorname'].'</option>';
}
?>
</select>
</div>
</div>
<p align="left">
<label>Search Head Used<br />
</label>
</p>
<div>
<div align="left">
<select id="searchheadname" name="searchheadname">
</select>
</div>
</div>
</div>
<p align="left">
<label>Detector Settings</label>
<label><br />
</label>
</p>
<div>
<div align="left">
<textarea name="detectorsettings" cols="50" rows="12" id="detectorsettings"></textarea>
</div>
</div>
<p align="left">
<label>PAS Ref. (if known)<br />
</label>
</p>
<div>
<div align="left">
<input name="pasref" type="text" id="pasref" size="9" />
</div>
</div>
<p align="left"><label>Additional Comments</label>
</p>
<div>
<div align="left">
<textarea name="additionalcomments" cols="50" rows="12" id="additionalcomments"></textarea>
</div>
</div>
</p>
<p>
<label>
<div align="left">
<input name="uploadimages" type="submit" id="uploadimages" value="Upload Image(s)"/>
</div>
</label>
</p>
<p align="left"><label>Do you wish to make this find public?<br />
</label>
</p>
<div>
<div align="left">
<?php
mysql_connect("host", "user", "password") or die("Connection Failed");
mysql_select_db("database")or die("Connection Failed");
$query = "SELECT * FROM makepublicoptions";
$result = mysql_query($query);
?>
<select name="makepublic" id="makepublic">
<option value=''>Choose 'Yes' or 'No'</option>
<?php
while ($line = mysql_fetch_array($result, MYSQL_ASSOC)) {
?>
<option value="<?php echo $line['publicoption'];?>"> <?php echo $line['publicoption'];?> </option>
<?php
}
?>
</select>
</div>
</div>
<p align="left">
<input name="submit" type="submit" value="Submit" />
</form>
Sincere thanks and regards
Try this:
HTML
Use a <button> element isntead of a submit button. Forms should never have more than one 'submit' button.
<button name="uploadimages" type="button" id="uploadimages">Upload Image(s)</button>
JS
$(function() { // Is the same as $(document).ready(function() {
$('#uploadimages').on('click', function() {
$("#dialog").dialog({
modal: true
});
});
});
Javascript has three modal dialogs - alert(), confirm() and prompt(). What you need is a psuedo-dialog box, that essentially disables the page below and shows some custom HTML.
The jQuery UI plug in has some nice features that will let you do this with a minimum of code (see http://jqueryui.com/demos/dialog/ for an example of jQuery dialogs).
Once the HTML for your dialog is on the same page as your app, you should be all set for getting your submits and such working, since they'll all be in the same window.

Categories