Jump to content

Storing Active List Item as String


fagnonk

Recommended Posts

I have a list of options in an XML file that I have loaded in to a standard dropdown box. Each one of these options represents an individual XML file. I want to take the active option (the option which the user has selected in the dropdown box) and load it into a separate php file as a string. This is probably a lot clearer if we look at the code:

 

index.php:

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>Uploadify scriptData Sample</title>

<link rel="stylesheet" href="uploadify/uploadify.css" type="text/css" />
<script type="text/javascript" src="js/jquery-1.3.2.min.js"></script>
<script type="text/javascript" src="js/jquery.uploadify.js"></script>
<script type="text/javascript">

$(document).ready(function() {

$("#fileUpload2").fileUpload({
	'uploader': 'uploadify/uploader.swf',
	'cancelImg': 'uploadify/cancel.png',
	'script': 'uploadify/upload.php',
	'folder': 'files',
	'multi': true,
	'buttonText': 'Select Files',
	'checkScript': 'uploadify/check.php',
	'displayData': 'speed',
	'simUploadLimit': 2
});
});

</script>

<script type="text/javascript">
     	$(document).ready(function(){
		$.ajax({
			type: "GET",
			url: "galleries.xml",
			dataType: "xml",
			success: function(xml) {
				var select = $('#mySelect');
				$(xml).find('category').each(function(){
					var title = $(this).find('title').text();
					select.append("<option>"+title+"</option>");
				});
				select.children(":first").text("please make a selection").attr("selected",true);
			}
		});
	});
</script>

</head>
<body>
<form>
     		<select id="mySelect">
     			<option>loading</option>
     		</select>
     	</form>
	<a href="javascript:$('#fileUpload2').fileUploadStart()">Start Upload</a> |  <a href="javascript:$('#fileUpload2').fileUploadClearQueue()">Clear Queue</a>
</body>
</html>

 

galleries.xml:

<?xml version="1.0" encoding="UTF-8"?>
<content>

<category link="0">
	<title>Option One</title>
	<xml>xml/option1.xml</xml>
</category>
<category link="1">
	<title>Option Two</title>
	<xml>xml/option2.xml</xml>
</category>

</content>

 

 

upload.php:

<?php
if (!empty($_FILES)) {
    $tempFile = $_FILES['Filedata']['tmp_name'];
    $targetPath = $_SERVER['DOCUMENT_ROOT'] . $_GET['folder'] . '/';
    $targetFile =  str_replace('//','/',$targetPath) . $_FILES['Filedata']['name'];
   
    move_uploaded_file($tempFile,$targetFile);
}

$str = $_FILES['Filedata']['name'];
$fp = fopen('upload.xml', 'a+');
fwrite($fp, $str);
fclose($fp);

?>

This is the file where I would like to replace upload.xml ( in '$fp = fopen('upload.xml', 'a+');' ) with the option selected by the user in the drop down box. I suspect I need to load the selected option in to some sort of string but I am not sure how to capture it from the index.php file.

 

 

 

 

Link to comment
https://forums.phpfreaks.com/topic/159355-storing-active-list-item-as-string/
Share on other sites

I think the above post may be really complicated. To be clear, what I am interested in is a php method to store data from the drop down list without a submit button then I need to figure out a way to replace upload.xml ( in '$fp = fopen('upload.xml', 'a+');' ) with the option selected by the user in the drop down box.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.