By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
455,044 Members | 1,155 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 455,044 IT Pros & Developers. It's quick & easy.

Best way to get the user to select a picture.

P: n/a
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
Jul 17 '05 #1
Share this Question
Share on Google+
1 Reply


P: n/a
"Sims" <si*********@hotmail.com> wrote in message
news:c5************@ID-162430.news.uni-berlin.de...
How do I create a popup box to allows them to browse their machine and then upload the selected file to my server.
Use a file input:

<input id="local_image_file" name="user_image_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 LocalImageFileChanged() {
if(window.event) {
var image_path = event.srcElement.value;
var image_preview = document.getElementById('image_preview');
if(image_path.length > 0) {
image_preview.src = image_path;
}
else {
image_preview.src = 'preview_image.gif';
}
}
}

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

or

$content = file_get_contents($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).
(is it legal?)


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

This discussion thread is closed

Replies have been disabled for this discussion.