Jump to content

Simple upload.


rondog

Recommended Posts

I cannot figure out why this isnt working...the folder 'uploads' is set to 777 also. Im sure this is something simple and im just not seeing it. It keeps coming back saying it wasnt uploaded.

<?php
if(isset($_POST['uploadbtn'])) {
$fieldname = "thefile";
$filename = $_FILES[$fieldname]['name'];
if ($filename != '') {
	$target = "uploads/";
	$source = $_FILES[$fieldname]['tmp_name'];
	$moved = move_uploaded_file($source, $target);
	if($moved) {
		$status = "$filename has been successfully uploaded to $target";
	} else {
		$status = "$filename wasn't uploaded.";
	}
}
} else {
$status = "Please select a file.";
}
?>
<!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=iso-8859-1" />
<title>Untitled Document</title>
</head>

<body>
<h4><?=$status?></h4>
<form id="form1" name="form1" enctype="multipart/form-data" method="post" action="">
  <input type="file" name="thefile" id="thefile" /><br/>
  <input type="submit" name="uploadbtn" value="Upload" />
</form>
</body>
</html>

Link to comment
https://forums.phpfreaks.com/topic/96058-simple-upload/
Share on other sites

when I attempted to upload and wasn't successful, your snippet printed:

Array
(
    [thefile] => Array
        (
            [name] => thumb5.jpg
            [type] => image/jpeg
            [tmp_name] => /tmp/phpZxgLot
            [error] => 0
            [size] => 5119
        )

)

Link to comment
https://forums.phpfreaks.com/topic/96058-simple-upload/#findComment-491782
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.