Spixxx Posted March 12, 2006 Share Posted March 12, 2006 [code] <[?]php$file_name = $_POST['file_name'];$number = $_POST['number'];$submit1 = $_POST['submit1'];$submit2 = $_POST['submit2'];$folder = "upload/";if(!$submit1){echo "How many files are you uploading[?]<br><br>";echo "<[form] action='$PHP_SELF' method='post'>";echo "<input type='text' name='number' maxlength='1'>";echo "<br>";echo "<input type='submit' name='submit1' value='Create Form'>";echo "</[form]>";}if($submit1 == "Create Form"){echo "<[form] action='$PHP_SELF' method='post'>";for($x=0;$x<$number;$x++){echo "<input type='file' name='file_name'><br>";}echo "<input type='hidden' name='number' value='$number'>";echo "<input type='hidden' name='MAX_FILE_SIZE' value='1000000'>";echo "<input type='submit' name='submit2' value='Upload'>";echo "</[form]>";}if($submit2 == "Upload"){for($x=0;$x<$number;$x++){$file_name = $_FILES['uploadFile'. $x]['name'];$file_name = stripslashes($file_name);$file_name = str_replace("'","",$file_name);$copy = copy($_FILES['uploadFile'. $x]['tmp_name'],$file_name);if($copy){echo "$file_name was uploaded";}else{echo "$file_name | could not be uploaded!<br>";}}}[?]>[/code]First off dont mind the [?] and [form] etc, theyre not the problem, my file editor just str_replaces them to prevent errors.Anyway, I always get $file_name | could not be uploaded!What did I do wrong?? Quote Link to comment Share on other sites More sharing options...
hitman6003 Posted March 12, 2006 Share Posted March 12, 2006 You had the file_name variable in your second form, and then Uploadedfile or something like that in your upload php code...[code]<?php$number = $_POST['number'];$submit1 = $_POST['submit1'];$submit2 = $_POST['submit2'];$folder = "upload/";if(!$submit1){ echo "How many files are you uploading[?]<br><br>"; echo "<form action='$PHP_SELF' method='post'>"; echo "<input type='text' name='number' maxlength='1'>"; echo "<br>"; echo "<input type='submit' name='submit1' value='Create Form'>"; echo "</form>";}if($submit1 == "Create Form"){ echo "<form action='$PHP_SELF' method='post'>"; for($x = 0; $x < $number; $x++){ echo "<input type='file' name='file_name$x'><br>"; } echo "<input type='hidden' name='number' value='$number'>"; echo "<input type='hidden' name='MAX_FILE_SIZE' value='1000000'>"; echo "<input type='submit' name='submit2' value='Upload'>"; echo "</form>";}if($submit2 == "Upload"){ for($x = 0; $x < $number; $x++){ $file_name = $_FILES['file_name'. $x]['name']; $file_name = stripslashes($file_name); $file_name = str_replace("'","",$file_name); $copy = copy($_FILES['file_name'. $x]['tmp_name'],$file_name); if($copy){ echo "$file_name was uploaded"; } else { echo "$file_name | could not be uploaded!<br>"; } }}?>[/code] Quote Link to comment Share on other sites More sharing options...
Spixxx Posted March 12, 2006 Author Share Posted March 12, 2006 My bad, I fixed that before someone replied, thanks. But it still gets the same error... Quote Link to comment Share on other sites More sharing options...
hitman6003 Posted March 12, 2006 Share Posted March 12, 2006 [!--quoteo(post=354202:date=Mar 12 2006, 11:01 AM:name=Spixxx)--][div class=\'quotetop\']QUOTE(Spixxx @ Mar 12 2006, 11:01 AM) [snapback]354202[/snapback][/div][div class=\'quotemain\'][!--quotec--]But it still gets the same error...[/quote]Did you see the other things that I fixed...?Also, turn on error reporting to see exactly what your error is:[code]ini_set("display_errors", "1");ini_set("error_reporting", "E_ALL");[/code] Quote Link to comment Share on other sites More sharing options...
Spixxx Posted March 12, 2006 Author Share Posted March 12, 2006 I did, copied exact thing, didn't work. Error reporting didnt help... Quote Link to comment Share on other sites More sharing options...
Spixxx Posted March 12, 2006 Author Share Posted March 12, 2006 Eh, I tried a different way and it works[code]<?php$number = 5;$directory = "upload/";if ($_POST) {for ($i=0;$i<$number;$i++) {if (trim($_FILES['myfiles']['name'][$i])!="") {$newfile = $directory.$_FILES['myfiles']['name'][$i];move_uploaded_file($_FILES['myfiles']['tmp_name'][$i], $newfile);$j++;}}}if (isset($j)&&$j>0) echo "Your file(s) has been uploaded.<br>";echo "<form method='post' enctype='multipart/form-data'>";for($i=0;$i<$number;$i++) {echo "<input type='file' name='myfiles[]' size='30'><br>";}echo "<input type='submit' name='action' value='Upload'>";echo "</form>";?>[/code]But how can I echo links to the file(s) uploaded when done uploading?? 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.