Reputation: 13
I am using xampp on my local desktop and created an folder named image.
Path: C:/xampp/htdocs/mycreation/ch-5/images/
.
In ch-5 folder i have my php file and also images folder.
now how can i define a $target_dir
to that images folder.
Upvotes: 0
Views: 235
Reputation: 16142
for uploading files you can use move_uploaded_file
function, which takes the current file and the location you want to save that file.
$file_name = $_FILES['image']['name'];
$file_tmp = $_FILES['image']['tmp_name'];
$target_dir = "images/"; //images directory
if (move_uploaded_file($file_tmp, $target_dir . $file_name)) {
echo "Uploaded file";
else
echo "Failed to upload image";
Upvotes: 0
Reputation: 93
create one folder(uploads) inside htdocs/ch-5 and try this code,,..
move_uploaded_file($_FILES['file']['tmp_name'],"uploads/".$_FILES['file']['name']);
$image_path="uploads/".$_FILES['file']['name'];
Upvotes: 0
Reputation: 102
$target_dir = $_SERVER['DOCUMENT_ROOT']."/mycreation/ch-5/images/";
Upvotes: 0
Reputation: 136
You can define target dir something like:
$target_dir = "images/";
Upvotes: 1