0

I have this short, basic code:

<?php
    $username = $_POST['User'];
    $file = $_FILES['File'];
    $size = $_FILES['File']['size'];
    $name = $_FILES['File']['name'];
    $temp_name = $file['tmp_name'];
    $user_id = Data::getUserId($username);
    $target_path = "/---/---/profile_pics/" . $name;

    $sql = "INSERT INTO profile_photos (name, size, user_id) 
               VALUES ('{$name}', '{$size}', '{$user_id}');";
    mysqli_query($dbconnection, $sql);

    move_uploaded_file($temp_name, $target_path);
?>

Note, this is TESTING code so I may have not followed best practice.

I get the correct file information into my MySQL database. But I do not get the actual file moved in the directory.

Also, the database IS extracting the correct file size and file name so something is being passed to PHP that is accurate for sure.


I am passing the file from Java. Here is supplemental info on that end (in case anyone knows about that end; but I do not think the problem is here:

HttpClient client = new DefaultHttpClient();
HttpPost post = new HttpPost(url_select);
File file = new File(imagePath);
HttpResponse response = null;
MultipartEntity entity = new MultipartEntity();
ContentBody cbFile = new FileBody(file, "image/jpeg");
StringBody sb;  

try {
    sb = new StringBody(userName);
    entity.addPart("User", sb);
    entity.addPart("File", cbFile);
    post.setEntity(entity);
    response = client.execute(post);            
} 
4

2 回答 2

1

PHP 可能没有写入目标目录的权限。这可以解释为什么 PHP 有关于文件的信息,但不能将它移动到那个位置。

您可以尝试在同一位置向文件(fopen、fwrite 等)写入一些简单的内容,以验证权限设置是否正确。

如果您打开了 PHP 错误日志记录,您还应该在日志中看到关于此的注释。

祝你好运。

于 2013-03-13T19:33:55.090 回答
0

它可以仔细检查您的路径小子。这就是我的问题的答案。否则代码是正确的。

于 2013-03-14T18:41:27.717 回答