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
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
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
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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.