Jump to content

upload picture problem..


warhead2020

Recommended Posts

I have this problem

 

first.php

 

<code>

<script language="javascript" >

 

function addElement()

{

var ni = document.getElementById('myDiv');

var numi = document.getElementById('theValue');

var num = (document.getElementById('theValue').value -1 + 2);

numi.value = num;

var newdiv = document.createElement('div');

var divIdName = 'my'+num+'Div';

newdiv.setAttribute('id',divIdName);

newdiv.innerHTML = '<input type=file id=imgfile' + num + ' name=imgfile' + num + '><a href="javascript:remove('+divIdName+')">Remove</a>';

ni.appendChild(newdiv);

}

 

 

function remove(dId)

{

var ni = document.getElementById('myDiv');

var numi = document.getElementById('theValue');

var num = (document.getElementById('theValue').value -1 + 0);

numi.value = num;

ni.removeChild(dId);

}

 

</script>

 

<form name="frmUp" method="post" action="second.php">

           

          <p><a href="javascript:addElement()" >Add Upload Field</a></p>

            <p>

              <input type="hidden" value="0" id="theValue" name="theValue"/>

            </p>

            <table width="100%" border="0">

                  <tr>

                    <td>

                    <div id="myDiv">

              </div>

                    </td>

                  </tr>

                  <tr>

                    <td><label>

                      <input type="submit" name="button" id="button" value="Submit" />

                    </label></td>

                  </tr>

                </table>

            <div id="myDiv">

              </div>

          </form>

 

</code>

 

 

second.php

<code>

$theValue = $_REQUEST['theValue'];

echo "theValue " . $theValue;

for($i = 1;$i <= $theValue;$i++)

{

echo basename($_FILES['imgfile' . $i]['name']);

}

 

</code>

 

 

 

in the first.php file, i use javascript to create input dynamically. But the problem is, i can grab the "theValue" value but i cant grab the "basename($_FILES['imgfile' . $i]['name'])". I hope somebody out there can understand this and help me solve this problem. Thanx in advance.

Link to comment
https://forums.phpfreaks.com/topic/153126-upload-picture-problem/
Share on other sites

 

I have this problem

 

first.php

 

<script language="javascript" >

function addElement() 
{ 
var ni = document.getElementById('myDiv'); 
var numi = document.getElementById('theValue'); 
var num = (document.getElementById('theValue').value -1 + 2); 
numi.value = num; 
var newdiv = document.createElement('div'); 
var divIdName = 'my'+num+'Div'; 
newdiv.setAttribute('id',divIdName); 
newdiv.innerHTML = '<input type=file id=imgfile' + num + ' name=imgfile' + num + '><a href="javascript:remove('+divIdName+')">Remove</a>'; 
ni.appendChild(newdiv); 
} 


function remove(dId) 
{ 
var ni = document.getElementById('myDiv'); 
var numi = document.getElementById('theValue'); 
var num = (document.getElementById('theValue').value -1 + 0);
numi.value = num; 
ni.removeChild(dId); 
} 

</script>

<form name="frmUp" method="post" action="second.php">
            
           	 <p><a href="javascript:addElement()" >Add Upload Field</a></p>
            	<p>
            	  <input type="hidden" value="0" id="theValue" name="theValue"/> 
          	  </p>
            	<table width="100%" border="0">
                   <tr>
                    <td>
                    <div id="myDiv">
               		</div>
                    </td>
                  </tr>
                  <tr>
                    <td><label>
                      <input type="submit" name="button" id="button" value="Submit" />
                    </label></td>
                  </tr>
                </table>
            	<div id="myDiv">
               	</div>
          </form>

 

 

second.php

<?php
$theValue = $_REQUEST['theValue'];
echo "theValue " . $theValue;
for($i = 1;$i <= $theValue;$i++)
{
echo basename($_FILES['imgfile' . $i]['name']);
}
?>

 

 

 

in the first.php file, i use javascript to create input dynamically. But the problem is, i can grab the "theValue" value but i cant grab the "basename($_FILES['imgfile' . $i]['name'])". I hope somebody out there can understand this and help me solve this problem. Thanx in advance.

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.