문제

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.

도움이 되었습니까?

해결책

Try replacing

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

with

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

다른 팁

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.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top