Wrox Programmer Forums
|
PHP How-To Post your "How do I do this with PHP?" questions here.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the PHP How-To section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old June 30th, 2004, 04:28 AM
Friend of Wrox
 
Join Date: Jun 2004
Posts: 331
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to qazi_nomi
Default PHP file upload

Hi,

Does any one know or treid any PHP File Upload product/program that let me upload images only, not exectuable files
, and if I already have an image in my folder with the same name either change the name of that file or let me
give name to the image before it saves it. I tried many products if one has one thing, it has something else missing, or not user frendly at all.

Thanks


Love 4 all
__________________
(*_*)

Numan
--------------------------------------------------
It is not important what you get But important is  how you got it
 
Old July 1st, 2004, 10:53 AM
Authorized User
 
Join Date: Jun 2004
Posts: 16
Thanks: 0
Thanked 0 Times in 0 Posts
Default

why not make an application of your own?
you could set it to deny any filenames which don't end in .jpg, .gif, etc.
i would probably try to make something myself, even if just for the sake of getting more practice with writing php apps.
 
Old July 11th, 2004, 10:43 PM
richard.york's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 1,706
Thanks: 0
Thanked 6 Times in 6 Posts
Default

Have a look at my file upload article at:
http://p2p.wrox.com/topic.asp?TOPIC_ID=12104

You can see in this file a simple check of the MIME type.
Code:
            // image.  MIME type testing isn't foolproof, it is possible to spoof this.
            // The size testing, however, is not spoofable.

            if (($_FILES['userfile']['size'] <= 10000) && ($_FILES['userfile']['type'] == 'image/jpeg' || $_FILES['userfile']['type'] == 'image/pjpeg'))
            {
                // Give the file a new name to prevent one user from overwriting files
If you want something more foolproof, and don't mind the extra overhead you can also add a call to a function that returns the image's dimensions.

if (@getimagesize($_FILES['userfile']['tmp_name']))

This function call in most contexts would return the image's width and height in pixels as an array. Here I'm simply using the function to verify that a valid image file has been supplied.

See: http://www.php.net/getimagesize

I also added error supression because this function throws a warning if the file supplied is not a valid image.



Regards,
Rich

::::::::::::::::::::::::::::::::::::::::::
The Spicy Peanut Project
http://www.spicypeanut.net
::::::::::::::::::::::::::::::::::::::::::





Similar Threads
Thread Thread Starter Forum Replies Last Post
How to upload mp3 file using php abhi.sharma05 PHP How-To 4 November 1st, 2011 11:59 PM
Whole Folder upload(Multi file Upload) ramasamy_rams XML 1 September 9th, 2005 12:43 PM
upload a simple .php file scrowler Beginning PHP 3 November 15th, 2004 10:54 PM
File upload problems in PHP 4.3.2 clem_c_rock Pro PHP 2 November 1st, 2004 10:49 AM
php file upload reason1000 BOOK: Beginning PHP4/PHP 5 ISBN: 978-0-7645-4364-7; v5 ISBN: 978-0-7645-5783-5 0 June 7th, 2003 10:49 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.