Secure File Upload In PHP Web Applications article

Started on the old forum in November 2009 · view the original in the archive · old links redirect here

5 replies · 701 views · started 17 years ago · 1 min read

4 participants
Mysterio Lead · 630 posts #2

thanks Gill. Btw, you still angry? 😀

mysterio.al - programming is a functional art

GiLL Senior · 356 posts #3

Mysterio3 wrote: thanks Gill. Btw, you still angry? :D

no why should i angry ?8)enjoy its life mood change like day and night lol

left wap stuff

subzero Super moderator Fellow · 3,954 posts #4

UPLOAD.PHP

<form action="<?php echo $_SERVER['PHP_SELF'];?>" method="post" enctype="multipart/form-data" name="file_upload">
	<input type="file" name="file" id="file">
	<input type="hidden" name="execute" id="execute">
	<input type="submit" name="Submit" id="Submit" value="Submit">
</form>

<?php

// Upload and Rename File
if (isset($_POST['execute'])) {
 
$filename = $_FILES["file"]["name"];
$file_basename = substr($filename, 0, strripos($filename, '.')); // strip extention
$file_ext = substr($filename, strripos($filename, '.')); // strip name
$filesize = $_FILES["file"]["size"];
 
	if (($file_ext == ".doc" || $file_ext == ".docx")  &&  ($filesize < 200000)) {
		// rename file
		$newfilename = md5($file_basename) . $file_ext;
 
		if (file_exists("upload/" . $newfilename)) {
			// file already exists error
			$error = "You have already submitted this file.";
		} else {
			move_uploaded_file($_FILES["file"]["tmp_name"], "upload/" . $newfilename);
			echo "File uploaded successfully.";
		}
	} elseif (empty($file_basename)) {
		// file type error
		$error = "Please select a file to upload.";
	} else {
		// file selection error
		$error = "Only doc, docx, rtf, pdf, and txt files can be submitted online.";
		unlink($_FILES["file"]["tmp_name"]);
	}
}
?>

Easy Dont need too worry no more lol

32982398u2.gif qw9r1q2ur9.zip wuiusadf9.txt 39riweeswikfj.jar

this works real good can't execute php script with out the php in the name...

Visit: Chat4u.mobi - The New Lay Of being a site of your dreams! Visit: WapMasterz Coming Back Soon!


SCRIPTS FOR SALE BY SUBZERO Chat4u Script : coding-talk.com/f28/chat4u-mobi-script-only-150-a-17677/ - > Best Script for your site no other can be hacked by sql or uploaders. FileShare Script : coding-talk.com/f28/file-wap-share-6596/ -> Uploader you will never regret buying yeah it mite be old now but it still seems to own others... _______…

subzero Super moderator Fellow · 3,954 posts #6

that script i post there will not let users to upload php chell scripts

they can't execute php script with out the php in the name...

Read better mate next time i did tell ya about it

Visit: Chat4u.mobi - The New Lay Of being a site of your dreams! Visit: WapMasterz Coming Back Soon!


SCRIPTS FOR SALE BY SUBZERO Chat4u Script : coding-talk.com/f28/chat4u-mobi-script-only-150-a-17677/ - > Best Script for your site no other can be hacked by sql or uploaders. FileShare Script : coding-talk.com/f28/file-wap-share-6596/ -> Uploader you will never regret buying yeah it mite be old now but it still seems to own others... _______…

Sign in to reply.

Similar topics

Keyboard shortcuts

g f
Go to forums
g h
Go to your feed
g m
Go to messages
r
Reply (in a topic)
/
Search
j
Next post
k
Previous post
?
This list
Ctrl/⌘ + Enter
Send what you are writing
Ctrl/⌘ + B / I
Bold / italic while writing
Esc
Close