Jump to content

upload multiple file type form


bmbc

Recommended Posts

This is the html part which I'm sure is not right:

<form action="upload.php" method="post" enctype="multipart/form-data">
<p>name:
<input type="text" name="name[]" /></p>
<p>email:
<input type="text" name="name[]" /></p>
<p>phone:
<input type="text" name="name[]" /></p>
<p>choose area: <select name="area" size="1">
<option>Canberra Inner North</option>
<option>Canberra Belconnen</option>
<option>Canberra Gungahlin and Hall</option>
<option>Canberra Inner South</option>
<option>Canberra Weston Creek</option>
<option>Canberra Woden Valley</option>
<option>Canberra Tuggeranong</option>
<option>Queanbeyan</option>
</select>
</p>
<p>property address:
<input type="text" name="name[]" /></p>
<p>suburb name:
<input name="suburb[]" type="text" id="suburb" size="8" maxlength="12" />
<p>property type:
<input name="suburb[]" type="text" id="suburb" size="8" maxlength="12" />
<p>energy rating:
<input name="number[]" type="text" size="5" maxlength="10" />
<p>bedrooms:
<input name="number[]" type="text" size="5" maxlength="10" />
<p>block size:
<input name="number[]" type="text" size="5" maxlength="10" />
<p>
property description:
<br/>
<textarea name="describe" cols="60" rows="18">Please type no more than the approx. 200 words, deleting this message first.</textarea>
</p>
<p>Pictures:
<br/>
<input type="file" name="pictures[]" />
<br/>
<input type="file" name="pictures[]" />
<br/>
<input type="file" name="pictures[]" />
<br/><input type="file" name="pictures[]" />
<br/><input type="file" name="pictures[]" />
<input type="submit" value="Send" />
</p>

</form>

and this is the php part:
<?php
foreach ($_FILES["pictures"]["error"] as $key => $error) {
if ($error == UPLOAD_ERR_OK) {
$tmp_name = $_FILES["pictures"]["tmp_name"][$key];
$name = $_FILES["pictures"]["name"][$key];
move_uploaded_file($tmp_name, "data/$name");
}
}
?>


None of which works :(
Any help really appreciated.
Link to comment
Share on other sites

The HTML seems to be OK, for the PHP part, you can use this:

[code]for ($k=0; $k<count($_FILES['pictures']['name']); $k++) {
   if ($_FILES['pictures']['error'][$k] == '0') {
      if (move_uploaded_file($_FILES['pictures']['tmp_name'][$k],
      'uploads/' . $_FILES['pictures']['name'][$k])) {
         echo 'File ' . ($k+1) . ' uploaded successfully' . '<br />';
      }
   }
}[/code]
Link to comment
Share on other sites

<?php
for ($k=0; $k<count($_FILES['pictures']['name']); $k++) {
if ($_FILES['pictures']['error'][$k] == '0') {
if (move_uploaded_file($_FILES['pictures']['tmp_name'][$k],
'uploads/' . $_FILES['pictures']['name'][$k])) {
echo 'File ' . ($k+1) . ' uploaded successfully' . '<br />';
}
}
}
?>

That is your code above?
I renamed this one upload2.php and changed the link in the htm file but
I'm getting this error:

Warning: move_uploaded_file(uploads/claw.gif): failed to open stream: No such file or directory in /home/l/lukem/www/upload2.php on line 6

Warning: move_uploaded_file(): Unable to move '/home/l/lukem/www/upload/phphR7nZH' to 'uploads/claw.gif' in /home/l/lukem/www/upload2.php on line 6

Thanks for your help and hope you can see my error this time.
Link to comment
Share on other sites

Well, try this:
[code]$updir = '/home/l/lukem/www/uploads/'

for ($k=0; $k<count($_FILES['pictures']['name']); $k++) {
   if ($_FILES['pictures']['error'][$k] == '0') {
      if (move_uploaded_file($_FILES['pictures']['tmp_name'][$k],
      $updir . basename($_FILES['pictures']['name'][$k]))) {
         echo 'File ' . ($k+1) . ' uploaded successfully' . '<br />';
      }
   }
}[/code]
Link to comment
Share on other sites

Hi poirot,

Here is where my form is that I'm practising on trying to make work:

[a href=\"http://www.yabbit.net/myuploadform.htm\" target=\"_blank\"]http://www.yabbit.net/myuploadform.htm[/a]

(I have no idea why there is a text field right up the top when I can't see it in the htm but anyway the form
just doesn't work)

And then I changed the upload.php to what you gave me:

[code]<?php
$updir = '/home/l/lukem/www/uploads/'

for ($k=0; $k<count($_FILES['pictures']['name']); $k++) {
   if ($_FILES['pictures']['error'][$k] == '0') {
      if (move_uploaded_file($_FILES['pictures']['tmp_name'][$k],
      $updir . basename($_FILES['pictures']['name'][$k]))) {
         echo 'File ' . ($k+1) . ' uploaded successfully' . '<br />';
      }
   }
}

?> [/code]

And this is the error msg I get:

Parse error: syntax error, unexpected T_FOR in /home/l/lukem/www/upload.php on line 5

Also because I have radio buttons and text fields and text files as well as pictures etc to upload, my php
doesn't reflect that or even point to a error and success page.

Thx again.
Link to comment
Share on other sites

Wops, forgot the semi-colon:
[code]<?php
$updir = '/home/l/lukem/www/uploads/';

for ($k=0; $k<count($_FILES['pictures']['name']); $k++) {
   if ($_FILES['pictures']['error'][$k] == '0') {
      if (move_uploaded_file($_FILES['pictures']['tmp_name'][$k],
      $updir . basename($_FILES['pictures']['name'][$k]))) {
         echo 'File ' . ($k+1) . ' uploaded successfully' . '<br />';
      }
   }
}[/code]

?>

Link to comment
Share on other sites

Hi again ,

I spent from 8am till 8pm today working with code and actually now that I think of it I've been doing that for the last three days plus dreaming about code solutions! ARGHH - I've come to the conclusion that either I am incredibly dumb or I'm trying to understand something which would take at least three months of studying(for me at least or I'm thinking maybe never will I comprehend it).
Anyway, what I have worked out is there is a script in phpformgen that easily creates db tables but nothing else; a quick script at php will upload multiple files to your server folder but nothing else and dodupload will upload files as well but with the added benefit of restricting upload file size without my service provider's safe mode stopping it!
But none of it is good :( because I want a php script that will execute my files text and images to a folder on my site from the htm form I've already created and on top of it all I dream of having one that will automatically resize input images so no mucking around in photoshop with ppl uploading absurd file size formats. It would be a bonus to then have all this recorded in mysql db.
Pathetically I can only come up with the htm form :((

My business idea is quickly fading away. All for one form. *vicious*
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.