File Not Uploading PHP

File not uploading PHP

Make sure that in your form.. you put the enctype.

eg: <form method="post" enctype="multipart/form-data" action="index.php"></form>;

To check if files are successfully updated upon submitting the form. use print_r to see results.
print_r($_FILES);

Files not being uploaded to server using PHP script

You're using ~/upload/ with a tilde and slash as path.

You should remove all of the tildes and slashes by using upload/ as a relative path.

Or, as stated by sonic720 in a comment: /var/www/upload this will differ from server to server, so yours may be something like /var/users/www/public_html/upload that is another option.

Use upload/ if executing your script from the root of your server.

If executed from a sub-folder, you may need to adjust it to, and for example: ../upload/

Also check for folder permissions. Either 0755 or 0777, yet 0755 is safer to use.

  • About: __DIR__ & BASE_PATH

Consult: http://php.net/manual/en/function.dirname.php


Edit:

I noticed something else echo "Return Code: " . $_FILES["file"]["error"] . "<br>"; that should read as echo "Return Code: " . $_FILES["uploadedfile"]["error"] . "<br>";


Add error reporting to the top of your file(s) which will help during production testing.

error_reporting(E_ALL);
ini_set('display_errors', 1);

Files do not upload via PHP

You aren't moving the file to your server after uploading the temp file so it gets deleted

if ($uploadOk == 0) {
echo "Sorry, your file was not uploaded.";
// if everything is ok, try to upload file
} else {
if (move_uploaded_file($_FILES["fileToUpload"]["tmp_name"], $target_file)) {
echo "The file ". basename( $_FILES["fileToUpload"]["name"]). " has been uploaded.";
} else {
echo "Sorry, there was an error uploading your file.";
}
}

Files not uploading despite not reaching the file size limit

The error you're getting is related to POST data in general (which uploads go through), and is not specific to file uploads.

The PHP setting you're looking for is post-max-size. You should be able to fix your issue by increasing its value.

Relevant part from the docs:

Sets max size of post data allowed. This setting also affects file
upload. To upload large files, this value must be larger than
upload_max_filesize.

html/php not uploading files

try this code

<form method="post" action="upload.php" enctype="multipart/form-data">
<input name="upload[]" type="file" multiple="multiple" />
<input type="submit" name="submit" value="Upload Files" class="btn btn-default btn-sm"/>
</form>

Your PHP file

<?php
if(isset($_POST["submit"]))
{
if(count($_FILES['upload']['name'])) {
foreach ($_FILES['upload']['name'] as $key=>$file) {
move_uploaded_file($_FILES['upload']['tmp_name'][$key], './uploads/'.$file);
}
}

}
?>

Unable to upload image in php

In your form you are missing enctype

<form action="upload.php" method="post" enctype="multipart/form-data">

File upload form is not uploading

I fixed the problem with the help of @04FS. I wrongly changed "name" to "image_to_upload" in the $target_file variable after changing that back to "name" and adding the missing ' to the HTML code it worked and successfully uploaded the picture.

File upload not working | Php

I have try below code and it's work perfect.

<!DOCTYPE html>
<html>
<head>
<title>File Upload</title>
</head>
<body>

<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="POST" enctype="multipart/form-data">
<input type="file" name="csv_file">
<input type="submit" name="submit">
</form>

<?php
if (isset($_POST['submit'])) {
echo "<p>" . $_POST['csv_file'] . " => file input successfull</p>";
$target_dir = "images ";
$file_name = $_FILES['csv_file']['name'];
$file_tmp = $_FILES['csv_file']['tmp_name'];

if (move_uploaded_file($file_tmp, $target_dir . $file_name)) {
echo "<h1>File Upload Success</h1>";
} else {
echo "<h1>File Upload not successfull</h1>";
}
}
?>
</body>
</html>

Why is my PHP file upload code not working?

You are working on windows and you've told PHP a location that is inaccessible (i.e. /uploads linux path).

Since you are working in windows and your document root is C:\wamp\www\simpleupload

Which means, your files are located like this:

  • C:\wamp\www\simpleupload\index.php (your upload script)
  • C:\wamp\www\simpleupload\uploads (where the files should be uploaded)

Why don't you use absolute path like this:

$uploads_dir = getcwd() . DIRECTORY_SEPARATOR . 'uploads';

The getcwd() function will return the current working directory for the executing PHP script (in your case index.php), so the $uploads_dir will now look like this: C:\wamp\www\simpleupload\uploads

Try this.

File not uploading to directory

The file is uploaded to a temporary folder, as print_r($_FILES) showed, the actual file is /tmp/phpEo6Gu5.

You have to use move_uploaded_file() to move this file to its final destination. Example:

move_uploaded_file($_FILE['thumbnail']['tmp_name'], 'img/final_name.png');

Do not trust $_FILE['thumbnail']['name'] or $_FILE['thumbnail']['type'] as safe and valid, because this comes from client-side and can be twisted by an ill-intentioned user to exploit security issues in your site.

In addition, make sure the user account your script runs with has permission to write to the final directory. Easy way to solve that would be running chmod 777 img in your shell (gives full read+write+execute permission to everyone in folder img).



Related Topics



Leave a reply



Submit