Pergunta

I can insert the folder path into the database but the picture file doesn't seem to move into that folder?

$pic = $_POST['pic'];

$picName= $_FILES['pic']['name'];

$type = $_FILES['pic']['type'];

$tmp = $_FILES['pic']['tmp'];

$picPath = "/pictures/";

  if(is_uploaded_file($tmp)) {
        if(move_uploaded_file($tmp, $picPath . $picName)) {
            echo "congrats! Image is uploaded.";
        }
        else {
            echo "Sorry, couldn't move your picture.";
        }
    }
    else {
        echo "Sorry, couldn't upload your picture.";
    }

$picPath = $picPath . $picName;

mysql_query("INSERT INTO User(pic) VALUES ('$picPath')");

I get this echo message: Sorry, couldn't upload your picture.

The php files is saved on public_html folder, and I have a pictures folder where I want to move the users pictures into.

The insertion works as I can store the $picPath in my database, but the picture don't get stored in my folder.

Foi útil?

Solução

Try replacing

$tmp = $_FILES['pic']['tmp'];

with

$tmp = $_FILES['pic']['tmp_name'];

Outras dicas

1) check folder permissions if its writable or not.
2) make sure your path is same with the same folder name in code as well.
3) Try to change from this $picPath = "/pictures/"; to something like this $picPath = "pictures/"; removed forward slash.

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top