Skip to content
View in the app

A better way to browse. Learn more.

Web Designer Forum

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

how do i restrict file type uploads

Featured Replies

Hi all after much time trying to wok out how to upload a file from a contact form to a server i have done it now how do i restrict it so that it only allows jpg as i would imagine hackers could upload anything to the server ?

 

here is my php

 

<?php

$target_path = "uploads/";

 

$target_path = $target_path . basename( $_FILES['uploadedfile']['name']);

$_FILES['uploadedfile']['tmp_name'];

$target_path = "uploads/";

 

$target_path = $target_path . basename( $_FILES['uploadedfile']['name']);

 

if(move_uploaded_file($_FILES['uploadedfile']['tmp_name'], $target_path)) {

echo "The file ". basename( $_FILES['uploadedfile']['name']).

" has been uploaded";

} else{

echo "There was an error uploading the file, please try again!";

}

 

?>

 

is there away i can make my script only allow jpg and jpeg extensions

 

and i supose when i have sorted that out i will need to no how to send it in an email any tutorials any one thanks every one

Hi, for image uploads, I would set an array of allowed file types

$oktypes = array('image/jpg', 'image/jpeg');

Then check the $_FILES array for the allowed types.

if (in_array($_FILES['uploadedfile']['type'], $oktypes)) {
carry on the form processing
}

Hope that helps.

Create an account or sign in to comment

Account

Navigation

Search

Search

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.