Jump to content


Photo

upload multiple file type form


  • Please log in to reply
7 replies to this topic

#1 bmbc

bmbc
  • Members
  • PipPip
  • Member
  • 21 posts

Posted 19 April 2006 - 04:23 AM

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.

#2 poirot

poirot
  • Members
  • PipPipPip
  • Advanced Member
  • 646 posts
  • LocationAustin, TX

Posted 19 April 2006 - 04:44 AM

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

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 />';
      } 
   }
}

~ D Kuang

#3 bmbc

bmbc
  • Members
  • PipPip
  • Member
  • 21 posts

Posted 19 April 2006 - 05:25 AM

<?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.

#4 poirot

poirot
  • Members
  • PipPipPip
  • Advanced Member
  • 646 posts
  • LocationAustin, TX

Posted 19 April 2006 - 03:33 PM

Well, try this:
$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 />';
      } 
   }
}

~ D Kuang

#5 bmbc

bmbc
  • Members
  • PipPip
  • Member
  • 21 posts

Posted 20 April 2006 - 03:55 AM

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:

<?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 />';
      } 
   }
}

?>

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.

#6 poirot

poirot
  • Members
  • PipPipPip
  • Advanced Member
  • 646 posts
  • LocationAustin, TX

Posted 20 April 2006 - 04:46 AM

Wops, forgot the semi-colon:
<?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 />';
      } 
   }
}

?>


~ D Kuang

#7 bmbc

bmbc
  • Members
  • PipPip
  • Member
  • 21 posts

Posted 20 April 2006 - 07:07 AM

Thanks but it still doesn't work , no error now just no action- no files found in uploads folder after submit.

#8 bmbc

bmbc
  • Members
  • PipPip
  • Member
  • 21 posts

Posted 20 April 2006 - 03:25 PM

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*




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users