Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- // Yahoo Answers: http://answers.yahoo.com/question/index?qid=20130615052503AAeEEVI
- function uploadErrorMsg( $error ){
- $errors = array(
- 1 => 'The uploaded file exceeds the Server\'s Maximum Allowable File Size',
- 2 => 'The uploaded file exceeds the Form\'s Maximum Allowable File Size.',
- 3 => 'The uploaded file was only partially uploaded, then interrupted or the connection was dropped.',
- 4 => 'No file was uploaded.',
- 6 => 'Missing a temporary folder. The server requires a temporary folder for file uploads.', // Server Setup Error
- 7 => 'Failed to write file to disk.', // Internal Server Error
- 8 => 'A PHP extension stopped the file upload.' // PHP Extension Library stopped the upload.
- );
- return $errors[(int) $error];
- }
- echo '<!DOCTYPE html>
- <html lang="en-us">
- <head>
- <title>Change Top 3 helicopters</title>
- </head>
- <body>
- <h1>Change Top 3 helicopters</h1>';
- if( isset($_FILES['file']) ){
- // Variable Defining
- $filename = $_POST['filename'];
- $product_number = (int) str_replace(Array('product','.txt'), '', $filename);
- $content = $_POST['content'];
- // Write Product File
- $pfn = 'product' . $product_number . '.txt';
- $fh = fopen($pfn, 'w') or die("Internal Error: Couldn't open File.");
- fwrite($fh, $content) or die('Internal Error: Couldn\'t write to File.');
- fclose($fh);
- // Upload Picture;
- $img = $_FILES['file'];
- $location = 'downloads/product' . $product_number . '.jpg';
- if( $img['error'] === UPLOAD_ERR_OK && move_uploaded_file($img['tmp_name'], $location)){
- echo 'File Uploaded!';
- }else if( $img['error'] !== UPLOAD_ERR_OK){
- echo 'Upload Error: ' . uploadErrorMsg($img['error']);
- }else{
- echo 'Internal Error: Couldn\'t move uploaded file to final location.';
- }
- echo '<br />';
- // Update Stats
- $statsFile = 'stats' . $product_number . '.txt';
- $cCount = (file_exists($statsFile))? (int) file_get_contents($statsFile) : 0;
- file_put_contents($statsFile, $cCount + 1);
- }else{
- echo 'Please Choose a file.';
- error_log('Failed to choose a file.' . PHP_EOL, 3, 'txt.txt');
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement