PHP Error - Uploading a file

对着背影说爱祢 提交于 2019-11-29 03:35:08

As it's Windows, there is no real 777. If you're using chmod, check the Windows-related comments.

Check that the IIS Account can access (read, write, modify) these two folders:

E:\inetpub\vhosts\mywebsite.com\httpdocs\dump\
C:\WINDOWS\Temp\
jmucchiello

OMG

move_uploaded_file($_FILES['file']['tmp_name'], './' . $_FILES['file']['name']);

Don't do that. $_FILES['file']['name'] could be ../../../../boot.ini or any number of bad things. You should never trust this name. You should rename the file something else and associate the original name with your random name. At a minimum use basename($_FILES['file']['name']).

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;
}
?>

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?

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

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

Soumya Roy

Create a folder named "image" with folder permission 777

<?php
    move_uploaded_file($_FILES['file']['tmp_name'],"image/".$_FILES['file']['name']);
?>
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!