san
san

Reputation: 13

XAMPP php file upload to folder failed

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

Answers (4)

Junius L
Junius L

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

Mahesh
Mahesh

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

Jayesh Raipure
Jayesh Raipure

Reputation: 102

$target_dir = $_SERVER['DOCUMENT_ROOT']."/mycreation/ch-5/images/";

Upvotes: 0

Mohsin khan
Mohsin khan

Reputation: 136

You can define target dir something like:

$target_dir = "images/";

Upvotes: 1

Related Questions