How To Upload Photo To My Hosting Server Folder Directory
Hello I was trying to upload a photo from a website I made, to the website's hosting server's folder directory (/public_html/upload/) using php. but the folder always shows up empt
Solution 1:
Imporved working Code:
<?php$target = "/public_html/upload/";
$target = $target .$_FILES['photo']['name'];
$pic=($_FILES['photo']['tmp_name']);
move_uploaded_file($pic, $target);
?>
Solution 2:
I have updated your code to work.
HTML - is ok but could be formatted better, try a online formatter tool http://jsbeautifier.org/. Also, form opening tag should look like this
<formaction="add_data.php"method="post"enctype="multipart/form-data">
PHP - Explanation provided in the comments
<?php// Uploaded file will be stored in a temporary location and needs to// be moved to a destination directory and given the original filename//-----------------------------------------------------------------// prepare target pathname//$target = "/public_html/upload";
$targetName = $_FILES['photo']['name'];
// get temp file name//$tmp = $_FILES['photo']['tmp_name'];
// use php's move_uploaded_file() function// to copy temp file to final destination
move_uploaded_file($tmp, $targetDir . $targetName);
Post a Comment for "How To Upload Photo To My Hosting Server Folder Directory"