Upload file return selction box of upload files
Posted: Sat Dec 18, 2010 3:07 pm
Here is what i need...
I need a way to upload a file via php ( which I have done )
yet when the submit button is pressed, I need ajax to return a selection box of the uploaded files
I have done this with a simple form, submit accesses upload.php, the upload.php uploads file to server then, creates a databse of the files uploaded via the username I provide.
Now I just need a way to return the selection box via ajax:
here is what I am working with so far;
index.php
Here is where I am confused becuase I need a way once the submit button is pressed, it sends the info to uploadf.js
Here is where I am using uploadf.js to get the vmuserid and vduserid from the src="uploadf.js?vmuserid=<?PHP echo htmlentities($vmuserid);?>&vduserid=<?PHP echo htmlentities($vduserid);?>">
then apply it to the uploadf.php string with the filename attached to q
ex: uploadf.php?vmuserid=$vmuserid&vduserid=$vduserid&q=$filename
now to get this to work q needs to be the filename i selected during upload this way I can pass it uploadf.php
I tried this with changing the submit button to a button and trying to use the onclick ( this.value) but I have no way of applying the input type="file" name="uploadedfile value or the max file size value to the upload file button.
Here is uploadf.js
Any Ideas would be great.
From my research on the net I have seen things like ( browsers are strict on the upload function, yet I would not have any issue if I can find a way to apply the input type "file value to the upload button, which I really need. instead of actually using a submit button.
I need a way to upload a file via php ( which I have done )
yet when the submit button is pressed, I need ajax to return a selection box of the uploaded files
I have done this with a simple form, submit accesses upload.php, the upload.php uploads file to server then, creates a databse of the files uploaded via the username I provide.
Now I just need a way to return the selection box via ajax:
here is what I am working with so far;
index.php
Here is where I am confused becuase I need a way once the submit button is pressed, it sends the info to uploadf.js
Code: Select all
<?php
$vduserid = $_GET["vduserid"];
//virtuemart user id
$vmuserid = $_GET["vmuserid"];
?>
<!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>
<title>test</title>
<link rel="stylesheet" href="../style.css" type="text/css" media="screen" />
<script language="javascript" src="uploadf.js?vmuserid=<?PHP echo htmlentities($vmuserid);?>&vduserid=<?PHP echo htmlentities($vduserid);?>"></script>
</head>
<body>
//Here is where the issue is///
<form enctype="multipart/form-data" action="uploadf.php" method="POST">
<input type="hidden" name="MAX_FILE_SIZE" value="99999100000" />
Choose a file to upload: <input name="uploadedfile" type="file" /><br />
<input type="submit" value="Upload File" />
</form><br>
//this is what I need
<form>
<input type="hidden" name="MAX_FILE_SIZE" value="99999100000" />
Choose a file to upload: <input name="uploadedfile" type="file" /><br />
<input type="button" value="Upload File" onclick (this.value) />
//how can I apply the max file size value and uploadedfile value to the button onclick event
</form>
<div id='txtHint'><b>Selection box will be built in uploadf.php and displayed within this div</b></div>
</body>
</html>
?>Here is where I am using uploadf.js to get the vmuserid and vduserid from the src="uploadf.js?vmuserid=<?PHP echo htmlentities($vmuserid);?>&vduserid=<?PHP echo htmlentities($vduserid);?>">
then apply it to the uploadf.php string with the filename attached to q
ex: uploadf.php?vmuserid=$vmuserid&vduserid=$vduserid&q=$filename
now to get this to work q needs to be the filename i selected during upload this way I can pass it uploadf.php
I tried this with changing the submit button to a button and trying to use the onclick ( this.value) but I have no way of applying the input type="file" name="uploadedfile value or the max file size value to the upload file button.
Here is uploadf.js
Code: Select all
// cross-broser fixes provided by Wes Friend
function gup( name )
{
name = name.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");
var regexS = "[\\?&]"+name+"=([^&#]*)";
var regex = new RegExp( regexS );
var results = regex.exec( window.location.href );
if( results == null )
return "";
else
return results[1];
}
var vmuserid_param = gup( 'vmuserid' );
var vduserid_param = gup( 'vduserid' );
function showUser(str)
{
if (str=="")
{
document.getElementById("txtHint").innerHTML="";
return;
}
if (window.XMLHttpRequest)
{// code for IE7+, Firefox, Chrome, Opera, Safari
xmlhttp=new XMLHttpRequest();
}
else
{// code for IE6, IE5
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.onreadystatechange=function()
{
if (xmlhttp.readyState==4 && xmlhttp.status==200)
{
document.getElementById("txtHint").innerHTML=xmlhttp.responseText;
}
}
xmlhttp.open("GET","uploadf.php?vduserid=" + vduserid_param + "&vmuserid=" + vmuserid_param + "&q="+str,true);
xmlhttp.send();
}Any Ideas would be great.
From my research on the net I have seen things like ( browsers are strict on the upload function, yet I would not have any issue if I can find a way to apply the input type "file value to the upload button, which I really need. instead of actually using a submit button.