开发者

PHP script for upload

I have written a script in PHP which is supposed to enable yuo to upload files. However, it can't seem to move the file to the right folder after it has uploaded it. Can anyone see what the problem is?

Here is the code:

    

    echo 'This is upload.php';
    $target_path = 'wwwroot/rsfleet.co.uk/ipad_test/sub/';
    echo 'Size of file: ';
    echo $_FILES['userfile']['size'];
    $target_path = $target_path . basename($_FILES['userfile']['name']);
    echo $target_path; 
    if (is_uploaded_file($_FILES['userfile']['tmp_name'])) {
        echo 'File uploaded OK.';
    } else {
   开发者_如何学C     echo 'Problem with file upload.';
    }
    if (move_uploaded_file(basename($_FILES['userfile']['tmp_name']), $target_path)) {
        echo 'The file ' . basename($_FILES['userfile']['name']) . ' has been moved';
    } 
    else 
    {
        echo 'Error moving file. Please try again.';
    }
    echo 'End of page.';

    


move_uploaded_file(basename($_FILES['userfile']['tmp_name']), ...)

This cannot work. It would only work if the temporary file was stored in the working directory (protip: it's not). Use the following instead:

move_uploaded_file($_FILES['userfile']['tmp_name'], ...)


Change

(move_uploaded_file(($_FILES['userfile']['tmp_name']),

to

(move_uploaded_file(($_FILES['userfile']['tmp_name']),

and it'll probably work

because $_FILES['userfile']['tmp_name'] has already full path


Check that the folder has the correct permissions, these are called a CHMOD command.

In FTP programs like Filezilla, you can set these permission by right mouse clicking on the folder and clicking 'File Permissions...'


I suppose problem is here:

$target_path = 'wwwroot/rsfleet.co.uk/ipad_test/sub/';

change to

$target_path = '/wwwroot/rsfleet.co.uk/ipad_test/sub/';

but it's just assumption.

also, basename is not necessary when moving files.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜