Jump to content

Passing a Javascript variable for file upload to next form page using PHP


upperbid

Recommended Posts

I'm good at PHP but don't know much about JavaScript. I am stuck on this job because I cannot figure out how to pass the file name(s) (there can be more than one) from the one page to the next or even how to print the file name(s) cause the code for uploading the file to the server is all in JavaScript. I need to be able to identify the file names somehow, and then to pass them using PHP. I have already passed everything else on the page, I just can't get this. Any help would be appreciated. Here is the code for the function:

 

function add_file(file) {
var j = i - 1;

var box = document.getElementById('file_list');
var num = box.length;
var file_exists = 0;

if (file_exists == 0) {
	// For Internet Explorer
	try {
		el = document.createElement('<input type="file" name="userfile[]" id="file_' + i + '" size="30" onChange="javascript:add_file(this.value);">');
	}
	// For other browsers
	catch (e) {
		el = document.createElement('input');
		el.setAttribute('type', 'file');
		el.setAttribute('name', 'userfile[]');
		el.setAttribute('id', 'file_' + i);
		el.setAttribute('size', '12');
		el.setAttribute('onChange', 'javascript:add_file(this.value);');
	}

	if(i==0){
	document.getElementById('frontfiles').innerHTML='No file Selected';
	}
	else
	{
	document.getElementById('frontfiles').innerHTML=i+'  files Selected';
	}


	document.getElementById('file_' + j).style.display

	document.getElementById('file_' + j).style.display = 'none';

	if (document.getElementById('list_div').style.display == 'none') {
		document.getElementById('list_div').style.display = 'block';
	}

	document.getElementById('files_div').appendChild(el);
	box.options[num] = new Option(file, 'file_' + j);

	i++;
}
}

 

And here is the form part:

 

</div>
	  </div>
		<div class="Printing3_Box1">
          <!--printContact-->
          <div class="uploadtxtCover">
          <!--uploadtxt-->
          <div style="float:left; width:239px;">
          <div class="chosefiles">
         <!-- <img src="images/chosefile.jpg" alt="Chose file" /><br />-->
         <span class="chooseend"> Files to upload (FRONT) : <span id="frontfiles">No file selected</span></span><br />
          </div>
          <div class="chosefiles">
          <div name="files_div" id="files_div" style="float:left;">
          
<input type="file" name="userfile[]" id="file_0" size="12"  onChange="javascript:add_file(this.value);">

</div>
</div>
<div class="chosefiles">
          <div name="list_div" id="list_div" style="display: none;">
<select multiple name="file_list" id="file_list" size="8" style="width:190px; height:22px;"></select>
<br>
<input type="button" id="remove_file_btn" value="Remove Selected" onClick="javascript:remove_file();">

</div>
</div>

 

Please keep this simple if you can help. I need to get names like this:

 

[folder]/[file name].[ext]

 

e.g. files/108078.jpg

 

If someone can tell me how to make the variable in PHP from the above code, I can probably easily pass the data along with the rest of the data I already got working. Thanks for any help

 

Robert

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.