Best way to get the user to select a picture.

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Sims

    Best way to get the user to select a picture.

    Hi,

    I have a web site where the users can propose articles to be published.
    But in the form the user can also send me a picture to illustrate the
    article
    they are proposing.

    Now I want to offer them 3 choices, either the picture comes from their
    machine, from my an image directory in my site or from the web.

    For the image from the web they must provide the URL as I don't think I can
    offer them a way of browsing around the internet.

    Now I have a couple of problems :),

    How do I create a popup box to allows them to browse their machine and then
    upload the selected file to my server.
    How do I copy the file from the web to my server, (is it legal?)
    How can I limit the file type, (only jpg and gif for example), and check
    that the file is 'safe'?
    How can I limit the size of the image, (in kb)?

    And last but not least how can I allow them to select an image from a
    predefined directory?
    I was thinking of displaying all the images but I can become a problem once
    I have quite a few.

    Many thanks in advance for your input.

    Sims


  • Chung Leong

    #2
    Re: Best way to get the user to select a picture.

    "Sims" <siminfrance@ho tmail.com> wrote in message
    news:c5makd$3ch 41$1@ID-162430.news.uni-berlin.de...[color=blue]
    > How do I create a popup box to allows them to browse their machine and[/color]
    then[color=blue]
    > upload the selected file to my server.[/color]

    Use a file input:

    <input id="local_image _file" name="user_imag e_file" type="file" size="80">

    See http://www.php.net/manual/en/features.file-upload.php

    You can attach an onchange handler to the control so that after a
    selection's been made, the user see what picture s/he will be uploading:

    function LocalImageFileC hanged() {
    if(window.event ) {
    var image_path = event.srcElemen t.value;
    var image_preview = document.getEle mentById('image _preview');
    if(image_path.l ength > 0) {
    image_preview.s rc = image_path;
    }
    else {
    image_preview.s rc = 'preview_image. gif';
    }
    }
    }

    The same can be done for the box where the user type in an URL.
    [color=blue]
    > How do I copy the file from the web to my server[/color]
    $f = fopen($url)
    while($data = fread($f, 4096)) {
    ...
    }
    fclose($f);

    or

    $content = file_get_conten ts($url);

    You are supposed to be able to use copy() to save remote files, but it
    didn't work when I tried (v.4.3.4).
    [color=blue]
    > (is it legal?)[/color]

    Depends on where you are. In China you'd get packed off to a re-education
    camp for creating such a site.


    Comment

    Working...