0

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

19
  • 2
    ` I like to work with fopen, file_get_contents, etc...` well, then get to work! What is your question? Where are you stuck? Commented Aug 25, 2010 at 23:21
  • Alright, alright! No need to get mouthy like that, I've edited the post... Commented Aug 25, 2010 at 23:26
  • @YouBook what is the problem with the code, what doesn't work? Looks okay so far. Commented Aug 25, 2010 at 23:28
  • as in the if($save_logo){ point, it outputs the else, which says "Error saving image" for what I call... Commented Aug 25, 2010 at 23:32
  • 1
    @You ahh, of course, you need to specify a file name - the directory i s not enough. Check SO to find your favourite function to build a random name/ID, but take note of the accepted answer to this question: stackoverflow.com/questions/1488288/php-random-name see e.g. here stackoverflow.com/questions/3347521/… Commented Aug 25, 2010 at 23:57

1 Answer 1

1

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

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.