tom c
tom c

Reputation: 329

Trouble getting images to upload in php/mysql

I've been working on a custom cms and I'm having trouble creating a form where a user can update the thumbnail associated with a given row. I have another page where they can do the initial upload, and it all works perfectly, but for some reason, even after copy and pasting the code directly to the update page, php returns errors for the following two lines:

move_uploaded_file($_FILES['thumbnail']['tmp_name'], "images/" . $_FILES['thumbnail']['name']);
$thumbnail_location = 'images/'. $_FILES['thumbnail']['name'];

The page leading to this one just contains a normal form where the upload input has a name of "thumbnail". Here is a little more of the related code although it does not seem to be the problem.

move_uploaded_file($_FILES['thumbnail']['tmp_name'], "images/" . $_FILES['thumbnail']['name']);
$thumbnail_location = 'images/'. $_FILES['thumbnail']['name'];
$id = $_GET['id'];



    $workset = mysql_query('SELECT * FROM work WHERE id='.$id.' LIMIT 1', $connection);
    while ($work = mysql_fetch_array($workset)) {

        mysql_query('UPDATE work SET thumbnail="'.$thumbnail_location.'" WHERE id='.$id.'');
    }

Upvotes: 3

Views: 206

Answers (2)

Musa
Musa

Reputation: 57

@mgrahy that's true well done. just here am trying to do the complete html form @tom c

<form method="post" action="" enctype="multipart/form-data">  
<input type ="thumbnail[]" multiple>
<input type ="submit" value="uplod">
</form>

Upvotes: 0

mgraph
mgraph

Reputation: 15338

you must add enctype="multipart/form-data" to your form :

<form method="post" action="" enctype="multipart/form-data">  

Upvotes: 3

Related Questions