Jump to content

[SOLVED] Image upload


denechtew

Recommended Posts

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>

<body>

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

<?

if(isset( $Submit))
{
//Als er op de Submitknop was geduwd doe:

if ($_FILES['imagefile']['type'] == "image/gif"){ 
copy ($_FILES['imagefile']['tmp_name'], "uploads/" . $_FILES['imagefile']['nam'])
or die ("Could not copy");

        echo ""; 
        echo "Name: ".$_FILES['imagefile']['name'].""; 
        echo "Size: ".$_FILES['imagefile']['size'].""; 
        echo "Type: ".$_FILES['imagefile']['type'].""; 
        echo "Copy Done...."; 
        } 
	  else {
            echo "<br><br>";
            echo "Could Not Copy, Wrong Filetype (".$_FILES['imagefile']['name'].")<br>";
        }
} 
?>
</form>
</body>
</html>

 

Hello guys,

 

i've got a problem, I read the tutorial of your website but i've got a problem, the image won't upload...

can someone help me?

Link to comment
https://forums.phpfreaks.com/topic/64810-solved-image-upload/
Share on other sites

I don't have anything setup my side to check the code, but this could be the solution:

 

<?php

if(isset( $Submit))
{
if ($_FILES['imagefile']['type'] == "image/gif"){ 
copy ($_FILES['imagefile']['tmp_name'], "uploads/" . $_FILES['imagefile']['name'])
or die ("Could not copy");

        echo ""; 
        echo "Name: ".$_FILES['imagefile']['name'].""; 
        echo "Size: ".$_FILES['imagefile']['size'].""; 
        echo "Type: ".$_FILES['imagefile']['type'].""; 
        echo "Copy Done...."; 
        } 

  else {
            echo "<br><br>";
            echo "Could Not Copy, Wrong Filetype (".$_FILES['imagefile']['name'].")<br>";
        }
} 
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>
<body>
<form name="form1" method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>" enctype="multipart/form-data">
<input type="file" name="imagefile" />
<br />
<input type="submit" name="Submit" value="Submit" />
</form>
</body>
</html>

Link to comment
https://forums.phpfreaks.com/topic/64810-solved-image-upload/#findComment-323368
Share on other sites

This just worked for me:

 

if ($imagefile != "")
{
   $target_path = "images/" . basename( $_FILES['imagefile']['name']);
   if(!move_uploaded_file($_FILES['imagefile']['tmp_name'], $target_path)) {
       echo "There was an error uploading the imagefile, please try again!";
   }   
}

Link to comment
https://forums.phpfreaks.com/topic/64810-solved-image-upload/#findComment-323399
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.