简体   繁体   中英

Upload file distant server

I'm using Formidable Pro and I create a hook to get all the data after the submit (Don't want to pay the addon API). I modify the action of the form to go to my PHP script after submitting. I just have a problem now, the form is used also to send images and PDF files.

I try to move the images and PDF files after the submitting, with move_uploaded_file but nothing works. I display the infos of $_FILES and I have this infos :

array(
        [name] => Array
            (
                [0] => compte_rendu_12-12-16.pdf
            )

        [type] => Array
            (
                [0] => application/pdf
            )

        [tmp_name] => Array
            (
                [0] => /tmp/phpHCenke
            )

        [error] => Array
            (
                [0] => 0
            )

        [size] => Array
            (
                [0] => 176072
            )

    )

Here is my PHP code :

$uploaddir = '/var/www/uploads/';
$uploadfile = $uploaddir . basename($_FILES['file70'][0]['name']);
echo '<pre>';
if (move_uploaded_file($_FILES['file70'][0]['tmp_name'], $uploadfile)) {
    echo "Upload with success";
} else {
    echo "Upload error";
}

I always have the message "upload error".

Any idea ?

The $FILES array should be referenced as

$_FILES['file70']['name'][0]

when multiple files are being uploaded

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM