0

plz help me I dont know how to make this work

<form action="accept-file.php" method="post" enctype="multipart/form-data">
    Your Photo: <input type="file" name="photo" size="25" />
    <input type="submit" name="submit" value="Submit" />
</form>

the accept-file.php is

if ($_FILES["file"]["error"] > 0) {
  echo "Error: " . $_FILES["file"]["error"] . "<br>";
} else {
  echo "Upload: " . $_FILES["file"]["name"] . "<br>";
  echo "Type: " . $_FILES["file"]["type"] . "<br>";
  echo "Size: " . ($_FILES["file"]["size"] / 1024) . " kB<br>";
  echo "Stored in: " . $_FILES["file"]["tmp_name"];
}
2

4 Answers 4

1

Can u try it?

$path = $_FILES['file']['name'];
if (file_exists($path)) {
    echo 'File already exists!';
} else {
    move_uploaded_file($_FILES['file']['tmp_name'], $path);
}
Sign up to request clarification or add additional context in comments.

Comments

1

I think you are missing something like this:

  move_uploaded_file($_FILES["file"]["tmp_name"],
  "../img/profiles/" . $_FILES["file"]["name"]);
  echo "Stored in: " . "../img/profiles/" . $_FILES["file"]["name"];

1 Comment

this is what I got when I try to upload image 0) { echo "Error: " . $_FILES["file"]["error"] . " "; } else { echo "Upload: " . $_FILES["file"]["name"] . " "; echo "Type: " . $_FILES["file"]["type"] . " "; echo "Size: " . ($_FILES["file"]["size"] / 1024) . " kB "; echo "Stored in: " . $_FILES["file"]["tmp_name"]; } move_uploaded_file($_FILES["file"]["tmp_name"], "../img/profiles/" . $_FILES["file"]["name"]); echo "Stored in: " . "../img/profiles/" . $_FILES["file"]["name"]; ?>
1

use move_uploaded_file(file,location)

you need to change your file field name to file instead photo

<input type="file" name="file" size="25" />

if don't change than use code like below to upload it.

move_uploaded_file($_FILES["photo"]["tmp_name"], "location/to/save/photo/with/extension");

Comments

0
<input type="file" name="photo" size="25" />

should be like

<input type="file" name="file" size="25" />

because you are looking for $_FILES["file"] not $_FILES["photo"];

make change to either your input name or the $_FILE[] as you wish.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.