Jump to content

Simple Image Uploader


LemonInflux

Recommended Posts

If u want just some directions then:

 

- Make a form with a: enctype="multipart/form-data" and a file field

- Use $_FILES for file names, size etc

- Use move_uploaded_file() to upload the file in your directory

- Return the file name u set it.

 

If u want a script that works then i can write a simple one for u.

Link to comment
https://forums.phpfreaks.com/topic/67150-simple-image-uploader/#findComment-336782
Share on other sites

jesirose and matthewhaworth have it right, as this isnt a request forum, instead a learning one. Anyway as this was quick and easy, here u go:

 

<form enctype="multipart/form-data" name="myform" method="post" action="">
    <input type="file" name="file" />
    <input type="submit" name="Submit" value="Submit" />
</form>

<?php
if($_FILES['file']['name'] != ""){
$filename = $_FILES['file']['name'];
$ext = strtolower(substr(strrchr($filename, '.'), 1));
$imagesExt = array('jpg', 'jpeg', 'png', 'gif', 'bmp');
$newPath = "mynewdir/{$filename}";
if(move_uploaded_file($_FILES['file']['tmp_name'], $newPath)){
	echo "File was uploaded succesfully<br />";
	if(in_array($ext, $imagesExt)){ 
		echo "Here is the image u uploaded";
		echo "<img src=\"{$newPath}\" />";
	}
}else{
	echo "There was an error uploading the file";
}
}
?>

 

Not tested though. If it has any syntax errors (missing " or ; or } or whatever) try debugging it yourself.

Link to comment
https://forums.phpfreaks.com/topic/67150-simple-image-uploader/#findComment-336790
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.