/    Sign up×
Community /Pin to ProfileBookmark

[RESOLVED] need help with uploading image

Hello, I am doing a webpage that allows people update their information, eg. address, phone number and upload personal icon.

<input name=”personal_icon” type=”file”>

Is there any method that can test $_FILE[personal_icon] either empty or not? What I want is something like this

If(empty($_FILE[personal_icon]))
{
Update all the information and upload icon
}else
{
Just update information
}

And another problem is that, after I uploaded icon, the system will redirect back to page personal.php, but the icon can’t be displayed properly until I press refresh button. I had tried use meta with refresh, it doesn’t work at all.?

Thank you for your help

to post a comment
PHP

2 Comments(s)

Copy linkTweet thisAlerts:
@OctoberWindJan 09.2009 — you can run a getimagessize() which set up an array[7].

[code=php]
[img]Array
(
[0] => 468 //width
[1] => 60 //height
[2] => 1 //imagetype
[3] => width="468" height="60" //height/width string (for <img> tags)
[bits] => 8
[channels] => 3 //3=rgb; 4=cmyk
[mime] => image/gif
)[/code]


You can either test
[code=php]
if ($img = getimagesize($_FILE[personal_icon])) {
if ($img["0"] || $img["1"] < 1)) //or any min/max file size
{
// process or reject based on file dimensions
}
[/code]


or you can validate based on mime-type:
[code=php]
$acceptableMimeTypes = array('image/bmp','image/jpeg', 'image/jpg','image/gif', 'image/png');
//note: you could instead create a regex that could accept image/*, but you may not want to since some types, like image/x-dwg, wouldn’t be used.

if ($img = getimagesize($_FILE[personal_icon])) {
if (!in_array($img["mime"],$acceptableMimeTypes)) {
// process or reject based on mime-type
} [/code]
Copy linkTweet thisAlerts:
@cs3pwauthorJan 09.2009 — thank you for your reply, but the code you suggested doesn't work. i just finger it out, i can simply use $size = $_FILES['personal_photo']['size'] to test it, :p thanks any way
×

Success!

Help @cs3pw spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.19,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...