Jump to content

[SOLVED] Return True upon file upload


GregL83

Recommended Posts

So another noob question from GregL83 :) .

I want to run some code only if a file is selected to be uploaded.

if(is_uploaded_file($_FILES["file"])) {
	if(($_FILES["file"]["size"] < 250000)) {
		if($_FILES["file"]["error"] > 0) {
		echo "Error: " . $_FILES["file"]["error"] . "<br />";
		}
		else {
		echo "Size: " . ($_FILES["file"]["size"] / 1024) . " Kb<br />";
		echo "Stored in: " . $_FILES["file"]["tmp_name"]."<br/>";
		echo "Type: " . $_FILES["file"]["type"] . "<br />";
		$ftype = substr($_FILES["file"]["type"],(strlen($_FILES["file"]["type"]))-3);
		echo $ftype."<br/>";
		move_uploaded_file($_FILES["file"]["tmp_name"], "images/main_image.".$ftype);
		echo "Stored in: "."images/".$_FILES["file"]["name"];
		}
	}
}

The line of importance is at the top!  I want the functions to run if a file is uploaded.  Let me know if you need the form, but i dont think it is nessecary to identify the proper method.  Thanks once again.  You guys are great!

Link to comment
https://forums.phpfreaks.com/topic/48715-solved-return-true-upon-file-upload/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.