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
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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.