Jump to content

Recommended Posts

Posted

Here's my code;

PHP

<?php

ini_set("upload_max_filesize", "8mb");

// $userfile is where file went on webserver

$userfile = $HTTP_POST_FILES['userfile']['tmp_name'];

// $userfile_name is original file name

$userfile_name = $HTTP_POST_FILES['userfile']['name'];

// $userfile_size is size in bytes

$userfile_size = $HTTP_POST_FILES['userfile']['size'];

// $userfile_type is mime type e.g. image/gif

$userfile_type = $HTTP_POST_FILES['userfile']['type'];

// $userfile_error is any error encountered

$userfile_error = $HTTP_POST_FILES['userfile']['error'];

// userfile_error was introduced at PHP 4.2.0

// use this code with newer versions

// put the file where we'd like it

$upfile = 'upload/'.$userfile_name;

// is_uploaded_file and move_uploaded_file

if (is_uploaded_file($userfile))

{

if (!move_uploaded_file($userfile, $upfile))

{

echo '<p><strong>Error:</strong> Could not move file to destination directory.<p>';

exit;

}

} else {

echo '<p><strong>Error:</strong> Possible file upload attack. Filename: '.$userfile_name.'</p>';

}

echo '<p>Success! File uploaded successfully. Filename: '.$userfile_name.'.</p>';

?>


Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...