I am selecting an image through i am getting name of a image. now i want to save that image in specific folder. here is my html code for photo_upload.php below:-
<html>
<body>
<form enctype="multipart/form-data">
<label>enter name :</label>
<input type="text" name="txt" /><br><br>
<label>Add your file here :</label>
<input type="file" id="upload" name="upload"><br><br>
<input type="submit" value="submit">
</form>
</body>
</html>
<?php
ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
error_reporting(E_ALL);
echo "hello to uploadprocessor page";
$name=$_REQUEST['txt'];
$image=$_REQUEST['upload'];
echo "<br><br> $name <br> $image";
$target_dir = "/var/www/html/php_example/photo_upload prg/new photos folder/";
$target_file = $target_dir . basename($_FILES["$image"]["name"]);
$uploadOk = 1;
if ($uploadOk == 0) {
echo "Sorry, your file was not uploaded.";
// if everything is ok, try to upload file
} else {
if (move_uploaded_file($_FILES["$image"]["tmp_name"], $target_file)) {
echo "The file ". basename( $_FILES["tmp_name"]["name"]). " has been uploaded.";
} else {
echo "Sorry, there was an error uploading your file.";
}
}
?>