0

I want to allow a user the upload an image (file) for their profile picture, on my website. They upload the image via an HTML form, but I am having trouble moving the file to the folder I want it to. I don't want to mess with the php.ini file to change the upload path. I want to use move_uploaded_file(). I try and use $tmp= $_FILES['picture']['tmp_name'] and var_dump($tmp), but It keeps returning a value of (0). So, I think the problem has something to do with that. Here is my code,

Here is my HTML:

<form enctype="multipart/form-data" method="post" action="upload_img.php">
<input type="hidden" name="MAX_FILE_SIZE" value="32768"/>
<input type="text" name="name" value=""/>
<input type="file" name="picture" value="picture"/>
<input type="submit" name="submit" value="upload"/>
</form>

And my PHP:

<?php

define('GW_UPLOADPATH', 'images/');

$picture= $_FILES['picture']['name'];
$name= $_POST['name'];
$tmp= $_FILES['picture']['tmp_name'];

var_dump($picture);
var_dump($name);
var_dump($tmp);

$connect= mysqli_connect(//connect params)
or die('error connecting with the database');

$query= "INSERT INTO pics (pic, name) VALUES ('$picture', '$name')";

$target= GW_UPLOADPATH . $picture ;

if (move_uploaded_file($_FILES['picture']['tmp_name'], $target);))
{

mysqli_query($connect, $query)
or die('error with query');
}

?>
4
  • Have you tried dumping $_FILES['picture'] yet? Mar 19, 2012 at 22:42
  • i get array(5) { ["name"]=> string(9) "aaron.jpg" ["type"]=> string(0) "" ["tmp_name"]=> string(0) "" ["error"]=> int(2) ["size"]=> int(0) Mar 19, 2012 at 22:44
  • 2
  • I already know the errors. What I don't get, is why am I getting it? I changed the MAX_FILE_SIZE to 100kb and the image is only 93kb and I still get an error. Mar 19, 2012 at 22:54

1 Answer 1

1

Your issue likely has something to do with php's upload_max_filesize and post_max_size. Check those 2 settings in your php.ini and make sure the file you are trying to upload isn't larger than either of them.

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.