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
Why Don't PHP Attributes Allow Functions
What's an Actual Use of Variable Variables
PHP Read_Exif_Data and Adjust Orientation
Get Custom Product Attributes in Woocommerce
Mysql_Real_Escape_String VS Addslashes
Create New Variables from Array Keys in PHP
How to Get a Div Content in PHP
Calculate the Time When the Sun Is X Degrees Below/Above the Horizon
Using PHP/Apache to Restrict Access to Static Files (Html, CSS, Img, etc)
Ajax File Download Using Jquery, PHP
MySQL - Count Total Number of Rows in PHP
Combinations, Dispositions and Permutations in PHP
Custom Pagination View in Laravel 5
How to Install PHP-Curl in Ubuntu 16.04
How to Echo a MySQLi Prepared Statement
How to Display a MySQL Error in PHP for a Long Query That Depends on the User Input