Move_Uploaded_File() Function Is Not Working

Php move_uploaded_file function not working properly

You must learn the code basics.
You should use the $_FILES super global for uploading files to your server. It is an associative array of uploaded file items and some of their properties.

Also you must add enctype="multipart/form-data" to your HTML form.

EXAMPLE:

<form action="" method="post" enctype="multipart/form-data">
topic image: <input type="file" name="pic" accept="image/*">
<input type="submit" name="submit" value="submit">
</form>
<?php

if(isset($_POST['submit']))
{
//This is not a good file upload code sample. You have to improve it.
$image=$_FILES["pic"]["tmp_name"];
$imageName = $_FILES["pic"]["name"]
move_uploaded_file($image,'images/'.$imageName );
}
?>

move_uploaded_file was not working on server side

You have given the relative path for destination

You need to specify the absolute path to the function. move_uploaded_file()

The following line will help you

$tmp = dirname(__FILE__) . "/uploads/" . $file_name;
$ok = move_uploaded_file($file_tmp, $tmp);

move_uploaded_file never creates the folder itself, so you need to create the folder uploads manually.

Also set the uploads folder permission to 755

PHP Move_uploaded_file function not working

ok! after so many digging and some suggestions by @ADyson in the comments.
Come to know that if you put conditions for the file size and checking for the file size you come up with the specific file size but to upload files greater then 2MB have to change php.init max_file_size also.
But still you cant't able to move files to the another folder that is move_uploaded_files() do. I dont know the way to change that but anyone knows that really will appreciated.



Related Topics



Leave a reply



Submit