Jump to content

Recommended Posts

hi to everyone and sorry for my English. in a html form, a user can upload from one to four file intwo different category (A and B)

<table>
<tr>
<td><b><i>Categoria a</i><b/>
</td>
<td><b><i>Categoria b</i><b/>
</td>
</tr>
<tr>
<td style="vertical-align: top; width: 475px;"><br /><b>File 1a<b/></td>
<td style="vertical-align: top; width: 475px;"><br /><b>File 1b<b/></td>
</tr>
	<tr>
<td><br>
<input name="file" type="file">
</td>
<td><br>
<input name="file1" type="file"></td>
</tr>
	<tr>
<td> Luogo dello scatto *:<br>
<input name="luogo1" type="text"><br>
</td>
<td> Luogo dello scatto *:<br>
<input name="luogo2" type="text"> <br>
</td>
</tr>
<tr>
<td> Titolo  *:<br>
<input name="titolo1" type="text"><br>
</td>
<td> Titolo  *:<br>
<input name="titolo2" type="text"> <br>
</td>
</tr>
	
<tr>
<td style="vertical-align: top; width: 475px;"><br /><b>File 2a<b/></td>
<td style="vertical-align: top; width: 475px;"><br /><b>File 2b<b/></td>
</tr>
	<tr>
<td><br>
<input name="file2" type="file">
</td>
<td><br>
<input name="file3" type="file"></td>
</tr>

<tr>
<td> Luogo  *:<br>
<input name="luogo3" type="text"><br>
</td>
<td> Luogo *:<br>
<input name="luogo4" type="text"> <br>
</td>
</tr>
<tr>
<td> Titolo *:<br>
<input name="titolo3" type="text"><br>
</td>
<td> Titolo  *:<br>
<input name="titolo4" type="text"> <br>
</td>
</tr>

they are then passed to the upload.php file


..... for each file:

	$file_1 = rand(1000,100000)."-".$_FILES['file']['name'];
    $file_1_loc = $_FILES['file']['tmp_name'];
    $file_1_size = $_FILES['file']['size'];
    $file_1_type = $_FILES['file']['type'];    
    $folder1= "uploads/categoria_a/";
    
$file_2 = rand(1000,100000)."-".$_FILES['file1']['name'];
    $file_2_loc = $_FILES['file1']['tmp_name'];
    $file_2_size = $_FILES['file1']['size'];
    $file_2_type = $_FILES['file1']['type'];
    $folder2 = "uploads/categoria_b/";
    
and so on...
	

        
then the upload...    

                                        
                                                
if (move_uploaded_file($file_1_loc,$folder1.$final_file_1) || move_uploaded_file($file_2_loc,$folder2.$final_file_2) || move_uploaded_file($file_3_loc,$folder1.$final_file_3) || move_uploaded_file($file_4_loc,$folder2.$final_file_4))
                                                    
                                                                                    
                                                
                                                    {
                                                    $sql="INSERT INTO .. 
(here all the data entry part in the sql  table that works..... 
	 ,,,                              ','$caricateil')";
                                                    mysql_query($sql);    
	
                                        <script>
                                        alert("Invio dati eseguito correttamente. ");
                                        window.location.href='index.php?success';
                                        </script>
                                        <?php
            
                                                    } else     {
                                                            ?>
                                                            <script>
                                                            alert("Errore nell'invio dei dati");
                                                            window.history.back(1); 
                                                            </script>
                                                            <?php
                                                            }
                                                    } 
    
                                    } ......
	

well.. if I use the code
 
if (move_uploaded_file($file_1_loc,$folder 1.$final_file_1) || move_uploaded_file($file_2_loc,$folder 2.$final_file_2 )|| move_uploaded_file($file_3_loc,$folder 1.$final_file_3) || move_uploaded_file($file_4_loc,$folder 2.$final_file_4))
{
$sql="INSERT INTO ......

**Loads only the first of the 4 files** it finds even if the db is populated correctly with file name size....

If, on the other hand, I use

if (move_uploaded_file($file_1_loc,$folder 1.$final_file_1) &&amp;move_uploaded_file($file_2_loc,$folder 2.$final_file_2) && move_uploaded_file($file_3_loc,$folder 1.$final_file_3) &&amp;move_uploaded_file($file_4_loc,$folder 2.$final_file_4))

Works... but only if all 4 files are present.

However, a person can only upload one.. in position 1, 2, 3 or 4.....

If one of the 4 is empty, the upload stops. I hope I explained myself....
If I load files 1, 3 and 4, load only the first...

If I insert files 2 and 4, load only the 2 etc.
And also from error even if it uploads the first files...

I would like you to upload the files and continue the script regardless of which file is up-to-date...


I hope I have been clear.

Link to comment
https://forums.phpfreaks.com/topic/312584-help-with-file-upload/
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.