PHP Error - Uploading a file

后端 未结 8 1592
春和景丽
春和景丽 2020-12-16 13:36

I\'m trying to write some PHP to upload a file to a folder on my webserver. Here\'s what I have:



        
相关标签:
8条回答
  • 2020-12-16 14:01

    Another think to observe is your directory separator, you are using / in a Windows box..

    0 讨论(0)
  • 2020-12-16 14:03

    Try adding a path. The following code works for me:

    <?php
    
    if ( !empty($_FILES['file']) ) {
        $from = $_FILES['file']['tmp_name'];
        $to = dirname(__FILE__).'/'.$_FILES['file']['name'];
    
        if( move_uploaded_file($from, $to) ){
            echo 'Success';   
        } else {
            echo 'Failure';   
        }
    
        header('Location: http://www.mywebsite.com/dump/');
        exit;
    }
    ?>
    
    0 讨论(0)
  • 2020-12-16 14:03

    Warning: move_uploaded_file() [function.move-uploaded-file]: Unable to move 'C:\WINDOWS\Temp\phpA30E.tmp' to './people.xml' in E:\inetpub\vhosts\mywebsite.com\httpdocs\dump\upload.php on line 3

    is the important line it says you can't put the file where you want it and this normally means a permissions problem

    check the process running the app (normally the webservers process for php) has the rights to write a file there.

    EDIT:

    hang on a bit I jumped the gun a little is the path to the file in the first line correct?

    0 讨论(0)
  • 2020-12-16 14:04

    Add the IIS user in the 'dump' folders security persmissions group, and give it read/write access.

    0 讨论(0)
  • 2020-12-16 14:06

    Create a folder named "image" with folder permission 777

    <?php
        move_uploaded_file($_FILES['file']['tmp_name'],"image/".$_FILES['file']['name']);
    ?>
    
    0 讨论(0)
  • 2020-12-16 14:07

    We found using below path

    {['DOCUMENT_ROOT'] + 'path to folder'

    and giving everyone full access to the folder resolved the issue.

    Make sure to not reveal the location in the address bar. No sense in giving the location away.

    0 讨论(0)
提交回复
热议问题