Jump to content

need help planning, possible while loop


Lodius2000

Recommended Posts

so I wanna make an upload script that will allow for 10 photos to be uploaded at a time, all being part of a single photo blog entry, each with a corresponding caption. but I dont want 10 to be the maximum or minimum. I intend to have an edit entry page that displays the same upload and caption fields so that things can be changed. so on the edit page i want to set something up that if all 10 caption fields are populated then dynamically create a few more so that more photos can be uploaded in the same entry

 

i am thinking

 

while ($_POST[caption]....... and thats about all ive got

 

any help planning this out would be much appreciated

Link to comment
https://forums.phpfreaks.com/topic/127465-need-help-planning-possible-while-loop/
Share on other sites

hrm... but my js knowledge is nonexistent, how do you think it could be done in php, page refresh doesnt bother me, my companies cms uses a page refresh for things like this, you get to the last available field and click 'save and continue editing', page refereshes and suddenly there is a new field at the bottom

This will not work with php because you cannot post back a value into a "file" type form field.  Maybe I'm wrong but if I recall, I tried this once and believe that I found out that it is a security violation to do so because I could put anything in that field and then automatically submit a form before you even knew what site you were visiting.  Within the blink of an eye I could have any file on your machine that I wanted.

Rob,

 

I cagree you cant post back file form fields but textarea's you can, so I want to make a new "file" and new "textarea" when all of the textarea's that i have a full

 

My point is, upon form submission(since that is how php works) the data that your user has already entered into the current file upload form fields will be lost and you will have to process them then and there.  At that point you can give them an option of adding ten more, but it won't be dynamic, not with file upload form fields.

Being a noob I would do this by putting a field at that top of the table asking them to designate how many files they plan to upload then set that in a variable and upon submit it would refresh and draw out the specific number of form fields they specified in that variable. If they want to do more after that then they need to start over.

Being a noob I would do this by putting a field at that top of the table asking them to designate how many files they plan to upload then set that in a variable and upon submit it would refresh and draw out the specific number of form fields they specified in that variable. If they want to do more after that then they need to start over.

That would work.

try this for fun ok.............

 

no settings needed choosing a file is only the file name no file posting...........

 

it all safe good fun!

 

u can select a file amount then post them pic's then select another amount.........

 

<?php

$self=$_SERVER['PHP_SELF'];

echo"<form method='POST' action='$self?cmd=a'>

<center>Please select number of photo's to upload!</center>

<br>
<br>

<center>

<select name='num'> ";

for($i=1; $i<11; $i++){

?>

<option value='<?php echo $i; ?>'><?php echo $i; ?></option>

<br>

<?php } ?>

</select>

<br>
<br>

<input type='submit' name='submit_boxs' value='Num pics//Add agin'>

</form>

</center>

<?php

if($_GET['cmd']=='a'){


if(isset($_POST['submit_boxs'])){


$pictures=$_POST['pictures'];

$num=$_POST['num'];

if($num==0){

echo"<center><br><br>SORRY PLEASE SELECT A NUMBER<br><br></center>";

exit;
}

echo"<form action='$self?cmd=pic' method='POST' enctype='multipart/form-data'>";





for($i=1; $i<$num+1; $i++){


?>

<br>

<br>

<center>

Pic<?php echo $i?> <input type="file" name="pictures[]"><br>

</center>

<?php } ?>

<br>

<br>

<center>

<input type="submit"  name="submit_photo" value="Send photos">

</center>

</form>

<?php 

} 
}
?>

<?php

if($_GET['cmd']=='pic'){



    foreach($_FILES["pictures"]["name"] as $p){
    	
    	if($p){
    		
    		echo "<br>Current file name: $p<br>";
    		
    	}else{
    		
    		echo"<center>PLEASE ADD A PICTURE!</center>";
    		
    		exit;
    	}

		}

}
?>

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.