CrabLab CrabLab - 4 months ago 52
PHP Question

PHP uploading an image

I am struggling to get PHP to process a posted image. The code which supposedly gets the tempory link is here:

$file = file_get_contents($_FILES["pic"]["name"]);

But I get the error

Warning: file_get_contents(): Filename cannot be empty

The image is definatly being posted as running this:

echo $_POST['pic'];

prints the name of the image.

I am not sure what I am doing wrong here? The field name from the form is pic.

Thanks for any help.


The image is then meant to be uploaded to Imgur.


HTMl included for reference:

<form class="form-horizontal" enctype="multipart/form-data" name="additem" role="form" method="POST" action="add.php">
<div class="alert alert-info" role="alert">Photos will be uploaded to <a href="">imgur</a></div>
<div class="form-group">
<label for="dept">Department</label>
<select class="form-control" name="dept" id="dept">

<div class="form-group">
<label for="pic">Image link</label>
<input class="form-control" type="file" id="pic" name="pic"></input>

<div class="form-group">
<label for="description">Description</label>
<textarea class="form-control" rows="3" id="description" name="description"></textarea>

<div class="form-group">
<button type="submit" class="btn btn-success">Add</button>


Found a fix:

A combination of adding the enctype to the form and adding a DOCTYPE to the markup fixed the issue.

Thanks to all who helped