Jump to content

File Uploader Help


Spixxx

Recommended Posts

[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??
Link to comment
https://forums.phpfreaks.com/topic/4754-file-uploader-help/
Share on other sites

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]
Link to comment
https://forums.phpfreaks.com/topic/4754-file-uploader-help/#findComment-16684
Share on other sites

[!--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]
Link to comment
https://forums.phpfreaks.com/topic/4754-file-uploader-help/#findComment-16689
Share on other sites

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??
Link to comment
https://forums.phpfreaks.com/topic/4754-file-uploader-help/#findComment-16704
Share on other sites

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.