searls03 Posted June 1, 2011 Share Posted June 1, 2011 can anyone tell me why this code doesn't work if it tries to upload like more than 3 files?: <?php include_once "secure/connect_to_mysql.php"; function genRandomString($length = 20) { $characters = '0123456789'; $string =''; for ($p = 0; $p < $length; $p++) { $string .= $characters[mt_rand(0, strlen($characters))]; } return $string; } if ($_POST['submit']) { $name = $_POST['name']; $id = $_POST['id']; $image = $_POST['image']; $event = $_POST['event']; $template = 'template.php'; $picture = '$name.png'; $id = genRandomString(); //this could be the uploaded picture $target_path = "images/"; foreach ($_FILES["uploadedfile"]["name"] as $key => $value) { $uploadfile = $target_path . basename($_FILES[uploadedfile][name][$key]); //echo $uploadfile; if (move_uploaded_file($_FILES['uploadedfile']['tmp_name'][$key], $uploadfile)) { echo $value . ' uploaded<br>'; } //we need just the filename - no extension $picture_name = pathinfo($picture, PATHINFO_FILENAME); $sql = "INSERT INTO pictures (name, id, image, event) VALUES('$name', '$id','images/$value','$event')"; $rs = mysql_query($sql) or die ("Problem with the query: $sql<br>" . mysql_error()); echo mysql_error(); } copy($template, "$event.php"); } ?> <form action="new.php" method="post" enctype="multipart/form-data"><input name="id" type="hidden" value=<?php echo $id; ?> /><br /> Event Name:<input name="event" type="text" /><input name="image" id="image" type="hidden" value="images/<?php echo $value; ?>" /><input type="hidden" name="MAX_FILE_SIZE" value="900000000000000000000000000000000000000000000000000000000000000000000000000" /> Choose a file to upload: <div id="dynamicInput"> <br>Picture:<input type="file" id="file" name="uploadedfile[]" onClick="addInput('dynamicInput');" > </div> <input type="button" value="Add another text input" onClick="addInput('dynamicInput');"> <br /><input name="submit" type="submit" value="submit" /></form> is it the code or something else? Quote Link to comment Share on other sites More sharing options...
fugix Posted June 1, 2011 Share Posted June 1, 2011 no errors are triggered? Quote Link to comment Share on other sites More sharing options...
searls03 Posted June 1, 2011 Author Share Posted June 1, 2011 no, it just clears the fields and goes back to before it started uploading, but nothing uploaded. :confused: Quote Link to comment Share on other sites More sharing options...
fugix Posted June 1, 2011 Share Posted June 1, 2011 have you tried inserting some code to debug? if (move_uploaded_file($_FILES['uploadedfile']['tmp_name'][$key], $uploadfile)) { echo $value . ' uploaded<br>'; }else {echo "error";} etc... Quote Link to comment Share on other sites More sharing options...
searls03 Posted June 1, 2011 Author Share Posted June 1, 2011 same thing happened, no errors came up though :( :( :confused: Quote Link to comment Share on other sites More sharing options...
fugix Posted June 1, 2011 Share Posted June 1, 2011 same thing happened, no errors came up though :( :( :confused: well if you didnt receive the error in the else statement then your file must have been moved..perhaps if you add some more smileys to your posts your question might be resolved... Quote Link to comment Share on other sites More sharing options...
searls03 Posted June 1, 2011 Author Share Posted June 1, 2011 well it didn't upload, I just checked. Quote Link to comment Share on other sites More sharing options...
searls03 Posted June 1, 2011 Author Share Posted June 1, 2011 so any other help? Quote Link to comment Share on other sites More sharing options...
kenrbnsn Posted June 1, 2011 Share Posted June 1, 2011 Since you're using Javascript to add new lines to your form, can you post that function? It may have something to do with your problem. Ken Quote Link to comment Share on other sites More sharing options...
searls03 Posted June 1, 2011 Author Share Posted June 1, 2011 var counter = 1; var limit = 10; function addInput(divName){ if (counter == limit) { alert("You have reached the limit of adding " + counter + " inputs"); } else { var newdiv = document.createElement('div'); newdiv.innerHTML = "<br><input type='file' name='uploadedfile[]'>"; document.getElementById(divName).appendChild(newdiv); counter++; } } Quote Link to comment Share on other sites More sharing options...
searls03 Posted June 1, 2011 Author Share Posted June 1, 2011 any other help? Quote Link to comment Share on other sites More sharing options...
fugix Posted June 1, 2011 Share Posted June 1, 2011 well you definitely over complicated the upload process..try to shorten your code and decrease the amount of possible things that can go wrong Quote Link to comment Share on other sites More sharing options...
searls03 Posted June 1, 2011 Author Share Posted June 1, 2011 ok, here is the main part: if ($_POST['submit']) { $name = $_POST['name']; $id = $_POST['id']; $image = $_POST['image']; $event = $_POST['event']; $template = 'template.php'; $picture = '$name.png'; $id = genRandomString(); //this could be the uploaded picture $target_path = "images/"; foreach ($_FILES["uploadedfile"]["name"] as $key => $value) { $uploadfile = $target_path . basename($_FILES[uploadedfile][name][$key]); //echo $uploadfile; if (move_uploaded_file($_FILES['uploadedfile']['tmp_name'][$key], $uploadfile)) { echo $value . ' uploaded<br>'; } //we need just the filename - no extension $picture_name = pathinfo($picture, PATHINFO_FILENAME); I dont want to change it really, because I do not want the couple of files that it can upload to stop unless I know what the problem is...... Quote Link to comment Share on other sites More sharing options...
fugix Posted June 1, 2011 Share Posted June 1, 2011 i notice that in this line $uploadfile = $target_path . basename($_FILES[uploadedfile][name][$key]); your forget to quote your indices and should be $uploadfile = $target_path . basename($_FILES['uploadedfile']['name'][$key]); also, you assign a value to $id twice...so your $_POST['id'] is being overwritten Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.