views:

32

answers:

1

I want to be able to open the provided URL (which is done via a form) that is an URL that will allow the server to save the file into a directory, for example:

http://www.google.co.uk/intl/en_com/images/srpr/logo1w.png

I want to save that logo into this directory:

img/logos/

Then it will add it to the database by giving it a random file name before so, e.g.

827489734.png

It will now be inserted to the database with the following:

img/logos/827489734.png

I do not want to use cURL for this, I like to work with fopen, file_get_contents, etc...

Cheers.

EDIT

$logo = safeInput($_POST['logo']);

if(filter_var($avatar, FILTER_VALIDATE_URL))
{
    $get_logo = file_get_contents($logo);
    $logo_directory = 'img/logos/';

    $save_logo = file_put_contents($logo_directory, $logo);

    if($save_logo)
    {
        $logo_path = $logo_directory . $save_logo;

A part of this code I need helping...

+1  A: 

You need to specify a full file name when doing a file_put_contents(). A pure directory name won't cut it.

Pekka
+1 and accepted.
YouBook