tags:

views:

88

answers:

3

Hello,

I have an file uploading site, it has an option of uploading through urls, what i am trying to do is whenever a user uploads through url, i check my database if a file exists that was uploaded through same url it displays the download url directly instead of uploading it again.

The data sent to uploading script is in array form like:

Array ( 
[0] => http://i41.tinypic.com/3342r93.jpg 
[1] => http://i41.tinypic.com/28cfub7.jpg 
[2] => http://i41.tinypic.com/12dsa32.jpg 
)

and the array used for outputing the results is in form like this:

Array
(
    [0] => Array
        (
            [id] => 43
            [name] => 3342r93.jpg
            [size] => 362750
            [descr] => 
            [password] => 
            [delete_id] => 75CE
            [upload_id] => 75F45CAE1
        )

    [1] => Array
        (
            [id] => 44
            [name] => 28cfub7.jpg
            [size] => 105544
            [descr] => 
            [password] => 
            [delete_id] => D392
            [upload_id] => 6676FD881
        )

    [2] => Array
        (
            [id] => 45
            [name] => 12dsa32.jpg
            [size] => 49000
            [descr] => 
            [password] => 
            [delete_id] => 54C9
            [upload_id] => A58614C01
        )

)

Now i want is that if the link http://i41.tinypic.com/28cfub7.jpg is already upload i just add it to output array but maintain it in a order (if the link added was 2nd in array the output result should also show it in 2nd)

So what fuction should be used to remove the matched urls from input array and a fuction to add it output array in the order no.

// edited

Yes unset will do the thing but i want to maintain the order:

For example after unsetting the array looks like this:

 Array ( 
    [0] => http://i41.tinypic.com/3342r93.jpg 
    // [1] was removed
    [2] => http://i41.tinypic.com/12dsa32.jpg 
    )

but the output array would be

    Array
    (
        [0] => Array
            (
                [id] => 43
                [name] => 3342r93.jpg
                [size] => 362750
                [descr] => 
                [password] => 
                [delete_id] => 75CE
                [upload_id] => 75F45CAE1
            )

// this will become [1], so how can i add another output[1] and shift other 
// items after it to [2], [3] and so on...
        [1] => Array
            (
                [id] => 45
                [name] => 12dsa32.jpg
                [size] => 49000
                [descr] => 
                [password] => 
                [delete_id] => 54C9
                [upload_id] => A58614C01
            )

    )

Thank You.

+1  A: 

Well, you can add it to the output array by doing something like:

$OutArray[2] = $element;

Where $element is another Array with the id, name, size (etc...) elements.

As for removing from the array:

unset($OutArray[2]);

You may want to read Array (PHP manual).

Matthew Iselin
please see the edited post
Shishant
On the manual page I linked to, search for "pepesantillan at gmail dot com" (It's from 19-Dec-2007 12:25). That array_insert function is what you're looking for.
Matthew Iselin
Thank you... this did the trick
Shishant
A: 

If you have an indexed array, you can remove a value by doing:

unset ($array[2]);

If you want to add an item to an array, use this shorthand of array_push (you don't need to specify an index!):

$array[] = "new object";

All documentation is on php.net/arrays

Wadih M.
please see the edited post
Shishant
A: 

Why don't use an if statement and/or file_exists() to see if the file is there. If you already have an array with the values then it just won't be uploaded again.

Paulo
please read the question properly
Shishant
The question is very fuzzy imo =P
anddoutoi