Me again (Huge Project...)

This is the code for my image upload, but it is not working...

I also want to set some parameters such as file size and to make sure that only photos are uploaded. The tutorials on the web is quite confusing...help please.

Thank you

if(isset($_POST['submitted']))
{

		$add="C:/xampp/htdocs/oefen/images/profile/";
		if(move_uploaded_file($userfile, $add))
		$content= 'Success';
		else
		$content= "Upload failed";
}
else
{
$content="	<FORM ENCTYPE='multipart/form-data' ACTION='index.php?mod=photo' METHOD='POST'>
		Upload this file: <INPUT NAME='userfile' TYPE='file' ID='file'/>
		<input type='hidden' value='TRUE' name='submitted'/>
		<INPUT TYPE='submit' VALUE='Upload Photo'></FORM>";
}




	$p=new Page('Profile Photo');
	$p->setHeading('Upload Profile Picture');

	$p->setContent($content);
	$p->printIt();
?>

Your Script Giving Following Error:

Fatal error: Class 'Page' not found in C:\xampp\htdocs\upload\test.php on line 22

First Solve This

Your Script Giving Following Error:

Fatal error: Class 'Page' not found in C:\xampp\htdocs\upload\test.php on line 22

First Solve This

The reason why the script is not working when you guys test it is because I created a Page class.

But at least it is uploading now but I am still stuck with the parameters such as file size etc...The same error message "Upload failed" can be displayed if its not an image or its too big.

Thanks guys

if(isset($_POST['submitted']))
{

		$uploaddir='C:/xampp/htdocs/oefen/images/profile/';
                $uploadfile = $uploaddir . basename($_FILES['userfile']['name']);
                
		if (move_uploaded_file($_FILES['userfile']['tmp_name'], $uploadfile))
		$message= 'Success';
		else
		$message= "Upload failed";
}
else
{
$content="	<FORM ENCTYPE='multipart/form-data' ACTION='index.php?mod=photo' METHOD='POST'>
		Upload this file: <INPUT NAME='userfile' TYPE='file' ID='file'/>
		<input type='hidden' value='TRUE' name='submitted'/>
		<INPUT TYPE='submit' VALUE='Upload Photo'></FORM>";
}




	$p=new Page('Profile Photo');
	$p->setHeading('Upload Profile Picture');

	$p->setContent($message.''.$content);
	$p->printIt();
?>
Member Avatar for rajarajan2017

Maxmimize the size of the uploaded files in configuration file. php.ini.

; Maximum allowed size for uploaded files.
; http://php.net/upload-max-filesize
upload_max_filesize = 128M

How can I rename the photo a user uploads to his email address which is stored in the session? I have a function called getEmail but I am not sure where to use it in the script above?

ask the one who made your script as i see you didn't create this, as you dont even know what your doing and how the code works, and also youre just showing us partial part of the code.

okay...to limit the file size you need

$_FILES["file"]["size"] < 50000))

in this example the limit file size is 50kb

if(($_FILES["file"]["type"] == "image/gif") || ($_FILES["file"]["type"] == "image/jpeg") || ($_FILES["file"]["type"] == "image/pjpeg))

only allows image such as gif and jpeg

to prevent uploading to big a file you can also limit it in your form

<INPUT TYPE='hidden' NAME='MAX_FILE_SIZE' VALUE='51200' />
Upload this file: <INPUT NAME='userfile' TYPE='file' ID='file'/>

recoment after this still use vaultdwellers script

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.