AJAX上传后将图像移动到服务器

时间:2013-07-10 14:10:30

标签: php jquery image-uploading

我正在捕获图像并将其上传到我服务器上的.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中我要做什么来将文件移动到我服务器上的方向吗? 就像我说的,上传工作正常......

1 个答案:

答案 0 :(得分: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);
?>