-1

I seem to be having some issues with my code, particularly with the fopen() command.

Is this the correct way to write images to a file? Would I also need to include r if I want to read from that image file later?

Here is what i have.

$boiler_img = $_FILES['boiler_image']; 
$dir = "images/boilers/";

$myfile = fopen("images/Boilers/"".$boiler_img.", "w") or die("Unable to open file!");
fwrite($myfile, $boiler_img);
Ethaan
  • 11,291
  • 5
  • 35
  • 45
Ph33ly
  • 663
  • 3
  • 13
  • 29
  • Thanks for the response! I tried it out but the file wasn't in the directory. Am I executing the command correctly? `move_uploaded_file($_FILES["boiler_image"]["tmp_name"], $dir.$_FILES["boiler_image"]["name"]);` – Ph33ly Apr 15 '15 at 02:56

1 Answers1

0

It looks like you're just handling a simple file upload. You can just use the tmp_name, name and the move_uploaded_file function to move it for you.

move_uploaded_file($_FILES["pictures"]["tmp_name"], $dir.$_FILES["pictures"]["name"];
Ohgodwhy
  • 49,779
  • 11
  • 80
  • 110