files: reading 
Author Message
 files: reading

Hello

I find it very hard to work with files and file uploads.
Now I need to make a script, that allows users to upload a file (html, image
or text)
and if it's a html file, check for "invalid" content
meaning, anything where they can invoke external code.

The function to do this should not be to difficult (search for http:// that
is not plain text an not in a img or a tag)
But what I find difficult, is that I think it would be better to check the
uploaded file, BEFORE I move it to it's final destination, this way, I only
write the necessary things to the file, instead of adding the code, and then
removing it...

Any ideas?
The thing I'm most confused about is move_uploaded_file (wich never works
for me, I use copy())

Another thing I could use some help with is this:
If a user uploads a file, I would like to restrain the hight and the width
of an image!
I think there is a way to check the height and width, but I don't know how
and if there is,  would like to resize it, that the width is fe. 200 pixels,
and the height should be
$new_height = $original_height / ($original_width/$new_width);
is there a way to do this automaticly

Thank you very much



Sat, 21 May 2005 04:21:47 GMT  
 files: reading

Quote:

> I find it very hard to work with files and file uploads.
> Now I need to make a script, that allows users to upload a file (html, image
> or text)
> and if it's a html file, check for "invalid" content
> meaning, anything where they can invoke external code.

> The function to do this should not be to difficult (search for http:// that
> is not plain text an not in a img or a tag)
> But what I find difficult, is that I think it would be better to check the
> uploaded file, BEFORE I move it to it's final destination, this way, I only
> write the necessary things to the file, instead of adding the code, and then
> removing it...

> Any ideas?

I don't understand what the problem is.  So scan it first, then if it's
OK, copy it.  What's the problem?  I must not understand what you're
trying to do.

Quote:
> The thing I'm most confused about is move_uploaded_file (wich never works
> for me, I use copy())

Why use move_uploaded_file() if copy() works?

Quote:

> Another thing I could use some help with is this:
> If a user uploads a file, I would like to restrain the hight and the width
> of an image!
> I think there is a way to check the height and width, but I don't know how
> and if there is,  would like to resize it, that the width is fe. 200 pixels,
> and the height should be
> $new_height = $original_height / ($original_width/$new_width);
> is there a way to do this automaticly

You can use gd (http://ww.php.net/manual/en/ref.image.php) or
ImageMagick (http://www.imagemagick.org/)

john



Sat, 21 May 2005 11:37:06 GMT  
 files: reading
move_uploaded_file() is better.  Do not use copy().  Read the PHP Manual (http://www.php.net/manual/en/features.file-upload.php).
It explains everything.  The function works for me like a charm.

Once a file is uploaded, use is_uploaded_file() to check if the upload was successful.

Then, check the mime-type with the $_FILES superglobal array (http://www.php.net/manual/en/language.variables.predefined.php).

If it's an image, then use getimagesize() to check the width and height.

If you need to resize the image, use imagecopyresize() (requires GD library).  imagecopyresampled() is better but requires GD 2.0.1
or later.

Quote:

> Hello

> I find it very hard to work with files and file uploads.
> Now I need to make a script, that allows users to upload a file (html, image
> or text)
> and if it's a html file, check for "invalid" content
> meaning, anything where they can invoke external code.

> The function to do this should not be to difficult (search for http:// that
> is not plain text an not in a img or a tag)
> But what I find difficult, is that I think it would be better to check the
> uploaded file, BEFORE I move it to it's final destination, this way, I only
> write the necessary things to the file, instead of adding the code, and then
> removing it...

> Any ideas?
> The thing I'm most confused about is move_uploaded_file (wich never works
> for me, I use copy())

> Another thing I could use some help with is this:
> If a user uploads a file, I would like to restrain the hight and the width
> of an image!
> I think there is a way to check the height and width, but I don't know how
> and if there is,  would like to resize it, that the width is fe. 200 pixels,
> and the height should be
> $new_height = $original_height / ($original_width/$new_width);
> is there a way to do this automaticly

> Thank you very much



Sat, 21 May 2005 14:45:40 GMT  
 
 [ 3 post ] 

 Relevant Pages 

1. File.read Vs. File.sysread performance...

2. disk file reads slow down for file sizes greater than 2 GB

3. error by file read in dll subroutine with in main opened File

4. binary file read/write acces

5. Random Access file reading in J...

6. File Reading in `J'

7. File Reading in 'J'

8. speed of file reading with resource fork

9. file read/write permissions

10. File Read/Write in Squeak

11. Remote Access pref file reading and writing

12. Clarion DOS file read/extract

 

 
Powered by phpBB® Forum Software