/    Sign up×
Community /Pin to ProfileBookmark

Checking extension

I have one more question. I want to know that how can I limit the upload to JPG file only. I got this code in reply of my message.

I want that the user can only upload JPG files only and not other files.

[CODE]
<?php
$fileatt = $_FILES[‘fileatt’][‘tmp_name’];
$fileatt_type = $_FILES[‘fileatt’][‘type’];
$fileatt_name = $_FILES[‘fileatt’][‘name’];

$uploads_directory = ‘/some/directory/’; // fill this in…
$upload_dir_and_filename = $uploads_directory . $fileatt_name;

if (is_uploaded_file($fileatt)) {
if ( move_uploaded_file($fileatt, $upload_dir_and_filename)) {
echo “success!”;
}else{
echo “fail!”;
}
}else{
echo “no file uploaded!”;

}
?>
[/CODE]

to post a comment
PHP

4 Comments(s)

Copy linkTweet thisAlerts:
@saud_iqbalauthorMay 30.2005 — I have another problem with this code. This code cannot allow me to write the text file if the user is not uploading the picture.

$fileatt = $_FILES['fileatt']['tmp_name'];

$fileatt_type = $_
FILES['fileatt']['type'];

$fileatt_name = $_FILES['fileatt']['name'];

$filename = $fileatt_name;

if ($_
FILES['$fileatt_type'] != "image/jpeg")

{

echo "only jpg picture allowed";

exit();

}



I want that if the user does not upload the picture then it should do the next work
Copy linkTweet thisAlerts:
@LiLcRaZyFuZzYMay 31.2005 — which [I]text file[/I]?
Copy linkTweet thisAlerts:
@VernonKMay 31.2005 — It would be best if you could post the entire handling script. It appears that a prior if() that isn't shown is causing the remainder of the script to not trigger.
×

Success!

Help @saud_iqbal 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.11,
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,
)...