3
Contributors
2
Replies
3
Views
7 Years
Discussion Span
Last Post by P0lT10n
0

Its the same way as any file upload with just restrictions about what type are accepted.

google w3school and look in the php section. That will probably help you a lot.

0

This is an example of an image upload

Validation code

// Recibe from post
$file_name = $_FILES["image"]["name"];
$file_type = $_FILES["image"]["type"];
$file_size = $_FILES["image"]["size"];
$file_error = $_FILES["image"]["error"];
$file_tmp = $_FILES["image"]["tmp_name"];

// Validate Image
if(!empty($file_name)){
	if($file_name > 120000){
		$msg .= "El peso supera los 120 kb !<br>";
	}
	if(!ereg(".gif",$file_name) && !ereg(".jpg",$file_name) && !ereg(".jpeg",$file_name)){
		$msg .= "The extension is invalid.<br>";
	}
	if($archivo_error > 0){
		$msg .= "Error when uploading.<br>";
	}
	if(file_exists("images/".$file_name)){
		$msg .= "The photo already exsists with that name.<br>";
	}
}

Only accepts .gif or .jpg or .jpeg...

And this is the upload code when is photo is valid

if(!empty($file_name)){
    echo "Uploading: ".$file_name."<br>";
    move_uploaded_file($file_tmp,"images/".$file_name);
}

And don't forget to put enctype="multipart/form-data" to upload a file

<form name="f1" action="" method="post" enctype="multipart/form-data">
    <input type="file" name="image" size="75" />
    <input type="submit" value="Send Photo"/>
</form>

Edited by P0lT10n: n/a

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.