0

我正在捕获图像并将其上传到我服务器上的 .php 脚本。AJAX 上传工作正常,但我不知道如何在 php 中处理上传的图像...

    // Upload files to server
function uploadFile(mediaFile) {
    path = mediaFile.fullPath;
    name = mediaFile.name;

    var options = new FileUploadOptions();
    options.fileKey="file";
    options.fileName=mediaFile.name;
    options.mimeType="image/jpeg";

    var params = new Object();
    params.fullpath = path;
    params.name = name;

    options.params = params;
    options.chunkedMode = false;

    var ft = new FileTransfer();
    ft.upload( path, "http://example.de/db/uploadPhoto.php",
        function(result) {
            alert("success");         
        },
        function(error) {
            alert("error");
        },
        options
        );
}

upload.php 文件:

<?php     
$uploaddir = '/home/strato/http/premium/rid/21/46/53452146/htdocs/tellthedj_dev/';
$uploadfile = $uploaddir . basename($_FILES['userfile']['name']);

echo '<pre>';
if (move_uploaded_file($_FILES['userfile']['tmp_name'], $uploadfile)) {
    echo "Datei ist valide und wurde erfolgreich hochgeladen.\n";
} else {
    echo "Möglicherweise eine Dateiupload-Attacke!\n";
}

echo 'Weitere Debugging Informationen:';
print_r($_FILES);

print "</pre>";

?>

你能告诉我我必须在 php 中做什么才能将文件移动到我服务器上的某个方向吗?就像我说的,上传工作正常......

4

1 回答 1

0

我用这段代码解决了它:

<?php
print_r($_FILES);
$new_image_name = "namethisimage.jpg";
move_uploaded_file($_FILES["file"]["tmp_name"], "/home/strato/http/premium/rid/..../".$new_image_name);
?>
于 2013-07-11T09:45:36.820 回答