• 0

[PHP] Image uploading


Question

7 answers to this question

Recommended Posts

  • 0

html form

<form action="upload.php" method="post" enctype="multipart/form-data">
Image:<input type="file" name="img" size="38" />
<input type="hidden" name="MAX_FILE_SIZE" value="1000000" />
<input type="submit" value="Submit" />
</form>

upload.php

$ext=array("jpg","jpeg","png","gif");
$size=$_FILES['img']['size'];
$img=$_FILES['img']['name'];
$file=pathinfo($img);
if(!in_array($file['extension'],$ext))
	{
	echo 'File type is not supported';
	}
elseif($size>1000000 or $size==0)
	{
	echo 'File size is greater then 1MB';
	}
else{
	move_uploaded_file($_FILES["img"]["tmp_name"], $_SERVER['DOCUMENT_ROOT']."/[b]directory[/b]/[b]imagename[/b]".$file['extension']);
	}

change the bold items to what you want and it should work fine. don't have the time to test it out atm.

  • 0

Thanks for replys, okay i come up with this:

<?php

$gettype = $_GET['type'];


if($gettype == "picture") {


$submit = $_POST['submit'];

if($submit == "Submit") {

$ext=array("jpg","jpeg","png","gif");
$size=$_FILES['img']['size'];
$img=$_FILES['img']['name'];
$file=pathinfo($img);
if(!in_array($file['extension'],$ext))
    {
    echo 'File type is not supported';
    }
elseif($size>1000000 or $size==0)
    {
    echo 'File size is greater then 1MB';
    }
else{
    move_uploaded_file($_FILES["img"]["tmp_name"], $_SERVER['DOCUMENT_ROOT']."/staffpictures/testname".$file['extension']);
    }


}

else {

echo("
<form action=\"profile.php?type=picture\" method=\"post\" enctype=\"multipart/form-data\">
<font class=\"secondheading\">Picture: </font>
<input name=\"img\" type=\"file\">
<input type=\"hidden\" name=\"MAX_FILE_SIZE\" value=\"1000000\" />
<input name=\"submit\" type=\"submit\" value=\"Submit\" />
</form>
");

}
}

But when i click submit, the file does show in the place it should be :s

Any ideas why?

Thanks, Tim

This topic is now closed to further replies.
  • Recently Browsing   0 members

    • No registered users viewing this page.