Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.
Moderator: General Moderators
novaks
Forum Newbie
Posts: 5 Joined: Thu Mar 18, 2004 9:34 am
Post
by novaks » Thu Mar 18, 2004 9:34 am
I made a multifielded upload form, it?s working but when I want to upload only a 5.files (but not all 14.files) it?s not working.
Help help help for this...
Code: Select all
upload.htm
<html><head><title>OBUR</title></head><body>
<form method="post" action="upload.php" enctype="multipart/form-data">
01. <input name="userfileї]" type="file"> <br>
02. <input name="userfileї]" type="file"> <br>
03. <input name="userfileї]" type="file"> <br>
04. <input name="userfileї]" type="file"> <br>
05. <input name="userfileї]" type="file"> <br>
06. <input name="userfileї]" type="file"> <br>
07. <input name="userfileї]" type="file"> <br>
08. <input name="userfileї]" type="file"> <br>
09. <input name="userfileї]" type="file"> <br>
10. <input name="userfileї]" type="file"> <br>
11. <input name="userfileї]" type="file"> <br>
12. <input name="userfileї]" type="file"> <br>
13. <input name="userfileї]" type="file"> <br>
14. <input name="userfileї]" type="file"> <br>
<input type="submit" name="addpicture" value="Upload" >
</form>
upload.php
<?
if (!empty($addpicture)) {
$prefix = time();
$_FILESї'userfile']ї'name']ї0] = $prefix.$_FILESї'userfile']ї'name']ї0];
$dest0 = $PicturePath.$_FILESї'userfile']ї'name']ї0];
move_uploaded_file($_FILESї'userfile']ї'tmp_name']ї0], $dest0);
$_FILESї'userfile']ї'name']ї1] = $prefix.$_FILESї'userfile']ї'name']ї1];
$dest1 = $PicturePath.$_FILESї'userfile']ї'name']ї1];
move_uploaded_file($_FILESї'userfile']ї'tmp_name']ї1], $dest1);
$_FILESї'userfile']ї'name']ї2] = $prefix.$_FILESї'userfile']ї'name']ї2];
$dest2 = $PicturePath.$_FILESї'userfile']ї'name']ї2];
move_uploaded_file($_FILESї'userfile']ї'tmp_name']ї2], $dest2);
$_FILESї'userfile']ї'name']ї3] = $prefix.$_FILESї'userfile']ї'name']ї3];
$dest3 = $PicturePath.$_FILESї'userfile']ї'name']ї3];
move_uploaded_file($_FILESї'userfile']ї'tmp_name']ї3], $dest3);
$_FILESї'userfile']ї'name']ї4] = $prefix.$_FILESї'userfile']ї'name']ї4];
$dest4 = $PicturePath.$_FILESї'userfile']ї'name']ї4];
move_uploaded_file($_FILESї'userfile']ї'tmp_name']ї4], $dest4);
$_FILESї'userfile']ї'name']ї5] = $prefix.$_FILESї'userfile']ї'name']ї5];
$dest5 = $PicturePath.$_FILESї'userfile']ї'name']ї5];
move_uploaded_file($_FILESї'userfile']ї'tmp_name']ї5], $dest5);
$_FILESї'userfile']ї'name']ї6] = $prefix.$_FILESї'userfile']ї'name']ї6];
$dest6 = $PicturePath.$_FILESї'userfile']ї'name']ї6];
move_uploaded_file($_FILESї'userfile']ї'tmp_name']ї6], $dest6);
$_FILESї'userfile']ї'name']ї7] = $prefix.$_FILESї'userfile']ї'name']ї7];
$dest7 = $PicturePath.$_FILESї'userfile']ї'name']ї7];
move_uploaded_file($_FILESї'userfile']ї'tmp_name']ї7], $dest7);
$_FILESї'userfile']ї'name']ї8] = $prefix.$_FILESї'userfile']ї'name']ї8];
$dest8 = $PicturePath.$_FILESї'userfile']ї'name']ї8];
move_uploaded_file($_FILESї'userfile']ї'tmp_name']ї8], $dest8);
$_FILESї'userfile']ї'name']ї9] = $prefix.$_FILESї'userfile']ї'name']ї9];
$dest9 = $PicturePath.$_FILESї'userfile']ї'name']ї9];
move_uploaded_file($_FILESї'userfile']ї'tmp_name']ї9], $dest9);
$_FILESї'userfile']ї'name']ї10] = $prefix.$_FILESї'userfile']ї'name']ї10];
$dest10= $PicturePath.$_FILESї'userfile']ї'name']ї10];
move_uploaded_file($_FILESї'userfile']ї'tmp_name']ї10], $dest10);
$_FILESї'userfile']ї'name']ї11] = $prefix.$_FILESї'userfile']ї'name']ї11];
$dest11 = $PicturePath.$_FILESї'userfile']ї'name']ї11];
move_uploaded_file($_FILESї'userfile']ї'tmp_name']ї11], $dest11);
$_FILESї'userfile']ї'name']ї12] = $prefix.$_FILESї'userfile']ї'name']ї12];
$dest12 = $PicturePath.$_FILESї'userfile']ї'name']ї12];
move_uploaded_file($_FILESї'userfile']ї'tmp_name']ї12], $dest12);
$_FILESї'userfile']ї'name']ї13] = $prefix.$_FILESї'userfile']ї'name']ї13];
$dest13 = $PicturePath.$_FILESї'userfile']ї'name']ї13];
move_uploaded_file($_FILESї'userfile']ї'tmp_name']ї13], $dest13);
$db->add_Picture($id,$fail0,$fail1,$fail2,$fail3,$fail4 ,$fail5,$fail6,$fail7,$fail8,$fail9,$fail10,$fail1 1,$fail12,$fail13);
}
?>
novaks
Forum Newbie
Posts: 5 Joined: Thu Mar 18, 2004 9:34 am
Post
by novaks » Fri Mar 19, 2004 6:02 am
It's possible neither of you knows what next?:?:
I dont belief....this is the php forum...I'm trying over a week.
Please help me.
markl999
DevNet Resident
Posts: 1972 Joined: Thu Oct 16, 2003 5:49 pm
Location: Manchester (UK)
Post
by markl999 » Fri Mar 19, 2004 6:32 am
Well, i've no idea where you are getting/setting those $fail values, but you can do the folowing for moving the uploaded files.
Code: Select all
<?php
if (!empty($_FILES)) {
$prefix = time();
$count = 0;
foreach($_FILES as $uploaded){
if(!empty($uploaded['name'][$count])){
$uploaded['name'][$count] = $prefix.$uploaded['name'][$count];
$dest[] = $PicturePath.$uploaded['name'][$count];
move_uploaded_file($uploaded['tmp_name'][$count], end($dest));
}
$count++;
}
//no idea what the following is supposed to do
//or where those $fail values get set
/*
$db->add_Picture($id,$fail0,$fail1,$fail2,$fail3,$fail4 ,$fail5,$fail6,$fail7,$fail8,$fail9,$fail10,$fail1 1,$fail12,$fail13);
*/
}
?>
novaks
Forum Newbie
Posts: 5 Joined: Thu Mar 18, 2004 9:34 am
Post
by novaks » Fri Mar 19, 2004 7:03 am
I got 2 function
1) is...
Code: Select all
<?php
function add_Picture($id,$fail0,$fail1,$fail2,$fail3,$fail4 ,$fail5,$fail6,$fail7,$fail8,$fail9,$fail10,$fail1 1,$fail12,$fail13)
{
$failavards0 = $_FILES['userfile']['name'][0];
$fail1 = $_FILES['userfile']['name'][1];
$fail2 = $_FILES['userfile']['name'][2];
$fail3 = $_FILES['userfile']['name'][3];
$fail4 = $_FILES['userfile']['name'][4];
$fail5 = $_FILES['userfile']['name'][5];
$fail6 = $_FILES['userfile']['name'][6];
$fail7 = $_FILES['userfile']['name'][7];
$fail8 = $_FILES['userfile']['name'][8];
$fail9 = $_FILES['userfile']['name'][9];
$fail10 = $_FILES['userfile']['name'][10];
$fail11 = $_FILES['userfile']['name'][11];
$fail12 = $_FILES['userfile']['name'][12];
$fail13 = $_FILES['userfile']['name'][13];
$sql = "insert into picture (id,nosaukums,apraksts,serijasnumurs,bilde,tehniskieparametri,funkcijasizskaidorjumi,tehniskiedati,rasejums,pielietosana,ipreitings,stativs,papildaprikojums,spc,pdf) values ('$id','$fail0','$fail1','$fail2','$fail3','$fail4','$fail5','$fail6','$fail7','$fails8','$fail9','$fail10','$fail11','$fail12','$fail13')";
$result = $this->insert($sql);
return $result;
}
?>
2) is...
Code: Select all
<?php
function insert($sql="")
{
if (empty($sql)) return false;
if (empty($this->CONN)) return false;
$conn = $this->CONN;
$results = mysql_query($sql,$conn);
if (!$results) return false;
$results = mysql_insert_id();
return $results;
}
?>
Hmmm ..
markl999
DevNet Resident
Posts: 1972 Joined: Thu Oct 16, 2003 5:49 pm
Location: Manchester (UK)
Post
by markl999 » Fri Mar 19, 2004 7:05 am
Well ... that's not too great, as the add_Picture function requires 14 pictures, it would be much better if it accepted an array of values, then it could handle any amount of images and not be restricted to 14 hard coded images ... imho
novaks
Forum Newbie
Posts: 5 Joined: Thu Mar 18, 2004 9:34 am
Post
by novaks » Fri Mar 19, 2004 7:13 am
As you see I'm not a pro ... onli a biginer
... end i don't know-how
markl999
DevNet Resident
Posts: 1972 Joined: Thu Oct 16, 2003 5:49 pm
Location: Manchester (UK)
Post
by markl999 » Fri Mar 19, 2004 7:17 am
I'd just move the sql stuff into the same code that loops around the $_FILES array, ie i wouldn't bother with the add_Picture or insert functions. Is the idea of the code just to 'upload a variable number of images, move them to a new directory and rename them, and insert the names into a database'? I ask because it looks like each picture is 'specific' as you're inserting each one into a separate database field.
novaks
Forum Newbie
Posts: 5 Joined: Thu Mar 18, 2004 9:34 am
Post
by novaks » Fri Mar 19, 2004 7:23 am
Yes idea of the code is just 'upload a variable number of images, move them to a new directory and rename them, and insert the names into a database'. And yes each picture is 'specific' because I inserting each picture into a separate database field.
markl999
DevNet Resident
Posts: 1972 Joined: Thu Oct 16, 2003 5:49 pm
Location: Manchester (UK)
Post
by markl999 » Fri Mar 19, 2004 7:35 am
I'd change the html form so that each file field matches the specifc image type it should contain, rather than use userfile[]. Look at the first user comment at
http://www.php.net/manual/en/features.f ... ltiple.php for an example of how to name each field so it has a unique name. This way you can then match the uploaded images to the database fields they should be going into. So you want to do something like :
1. Loop over the $_FILES array
2. Do your moving and renaming
3. Do 1 insert for each field (or dynamically build up a query and do it in one)
If you are still stuck with that then let us know and someone might whip up some example code for you if you're lucky