Home php教程 php手册 IIS+php服务器无法上传图片解决办法

IIS+php服务器无法上传图片解决办法

Jun 13, 2016 am 11:25 AM
php.ini upload main Method picture server test Purpose solve set up

主要目的就是测试我的php.ini没有设置upload_dir_tmp的值的时候,上传的文件临时保存在哪里的,经过这个测试发现原来在不配置php.ini的upload_dir_tmp的值的时候,默认的存储位置是在 C:windowstemp目录,并且临时文件是以.tmp为后缀存储的,该文件马上就会被删除,所以你想通过操作系统的文件修改搜索功能是无法找到的,也就无法找到upload_dir_tmp的默认路径是哪里。

IIS+php教程服务器无法上传图片解决办法

服务器上使用Apache2+PHP正常运行,换成IIS+PHP,先后出现了php.ini的环境变量无法读取,php中验证码无法显示的问题,如今又有人反应无法上传图片的问题。

   从IIS替换Apache2的过程仅仅是开启IIS,关闭Apache2,其它的没什么变化,但是却发生了如此多的差异,看样子IIS支持PHP还是有很多要进行修改的。

分析:

   根据上面的描述,我怀疑问题出在IIS的权限配置上,IUSR_MACHINE的帐户对upload没有写入的权限,于是进行权限修改,IIS下的权限,NTFS下的权限都进行修改,但是终究都没用,查找网络上的资料也没有相应的,对上传页面进行测试,流程为:

   swf文件调用save.php上传文件---->swf文件对上传的文件进行重命名--->名字返回给save.php--->显示出最后的名字。

   现在的问题一直停留在swf对文件重命名的这里,一直没有到显示出最后的名字,并且swf文件不参与上传过程,那就只能在save.php文件中进行问题查找了,在该文件中进行测试,最后显示的名字所使用的变量为fileName,于是插入下面的语句进行测试:

   echo "fileName=2008*****.gif";

   这句话的作用就是使得fileName有值,save.php能正常显示,先把原来的语句一句一句的进行屏蔽测试,都正常的返回了,但是当测试到:
    if (!@move_uploaded_file($f["tmp_name"], $dest_dir.'/'.$fileName)) header("HTTP/1.0 404 Not Found");
   这句话的时候问题出现了,不能上传,查找上下文,一直没发现tmp_name的变量,不过看意思是先把文件上传到一个临时文件,再挪动到目的位置,那这个tmp位置在哪里呢?是不是这个位置不可写,才导致了无法上传文件?

   查找网上资料,发现php.ini下面有2个地方关于上传的配置:
file_uploads = On                          这里设置是否允许HTTP上传,默认应该为ON的
   ;upload_tmp_dir=                          这里设置上传文件存放的临时位置

网上对于这2个地方的相关资料有:
I try to set up file uploading under IIS 7 and PHP 5.

First problem was to set 2 variables in php.ini

file_uploads = On           //这里是说php.ini文件这个地方设置成On

upload_tmp_dir = "C:Inetpubwwwrootuploads"    //这个路径就是自己设置的上传文件临时存储路径

For some reasons such directory name works,
but "upload_tmp" won't work.

The second problem was to set correct user rigths for upload folders where you try to save your file. I set my upload folder rights for the "WORKGROUP/users" for the full access. You may experiment by yourselves if you not need execute access, for example.

    我的php.ini中upload_tmp_dir是被注释的,没有启用,更没有设置,可是为什么Apache2却可以正常上传呢?难道问题真的出在这里?

解决:

   新建一个文件夹做临时上传目录,按照上面的英文说明修改php.ini中相应的那2项,把临时上传目录upload_tmp_dir设置成刚才建立的文件夹,把该文件夹的权限赋予“IUSR_计算机名”用户可写,重新启动IIS,上传试试,问题真的就这样解决了。


最终的分析答案:

   上面的内容写于09年,但是现在2010年7月我新增一台服务器,又出现了这个问题,同时再次按照上面的解决方法实施,在操作的过程中大概是由于哪里出了错,竟然没有成功,不得不抽出点时间来研究具体原因,找到了最终产生这个问题的原因如下。
    无法上传文件,不代表所有文件都无法上传,因为我的一个网站,flash调用fwrite()传头像之类的成功了,但是调用@move_uploaded_file($f["tmp_name"], $dest_dir.'/'.$fileName)这样的函数传照片的时候仍旧无法上传。
   经过我的分析,原因是由于fwrite()是传的二进制文件,而move_uploaded_file()传的是文本文件,而windows操作系统是区分这2种文件的 [参考php手册fwrite()函数的说明],这也就是说这2种不同的文件在php环境下上传时所存储的临时上传目录是不同的,由于在配置IIS环境下的PHP的时候,设置的临时目录为E:tmp,设置该目录的iusr用户可写,二进制文件即可上传,所以我怀疑该目录就是二进制文件上传临时文件的存储位置,那么move_uploaded_file()传的文本文件的临时文件存储位置在哪里呢?其实就是在上面的那段英文里面,upload_tmp_dir设置的路径就是了,但是我的几台服务器中,每台服务器的这个设置的值都是被注释掉的“no value”,为什么有的服务器可以上传,而有的服务器不可以上传呢?这也就回到了以前我提出的问题,为什么Apache2可以上传而iis不可以上传呢?
    这次我再次分析upload.php文件,分析其中造成该故障的代码具体内容如下:

// 检查是否有文件上传
    if (! $_FILES['upload'.$num]['name'] == ""){
      if ($_FILES['upload'.$num]['size']    1、 echo "文件上传路径:".$location.$_FILES['upload'.$num]['name'];
    2、echo "文件临时文件名:".$_FILES['upload'.$num]['tmp_name'];
    3、    move_uploaded_file($_FILES['upload'.$num]['tmp_name'],$location.$_FILES['upload'.$num]['name']) or $event = "Failure";
    } else {
     $event = "File too large!";
    }

   其中正常代码中第2句是不存在的,为了测试方便我加上来的,它的主要目的就是测试我的php.ini没有设置upload_dir_tmp的值的时候,上传的文件临时保存在哪里的,经过这个测试发现原来在不配置php.ini的upload_dir_tmp的值的时候,默认的存储位置是在 C:windowstemp目录,并且临时文件是以.tmp为后缀存储的,该文件马上就会被删除,所以你想通过操作系统的文件修改搜索功能是无法找到的,也就无法找到upload_dir_tmp的默认路径是哪里。

   既然找到了upload_dir_tmp的默认路径了,那么修改c:windowstemp的访问权限,赋予IUSR_用户可写,重启动IIS Admin服务,上传文件,终于成功了。这就是为什么我的多台服务器upload_dir_tmp的值都为空的时候有的可传,有的不可传的原因。


Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
2 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Repo: How To Revive Teammates
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Hello Kitty Island Adventure: How To Get Giant Seeds
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

How to set the scheduled time for publishing works on Douyin? How does it set the video duration? How to set the scheduled time for publishing works on Douyin? How does it set the video duration? Mar 27, 2024 pm 06:11 PM

Publishing works on Douyin can attract more attention and likes, but sometimes it may be difficult for us to publish works in real time. In this case, we can use Douyin's scheduled release function. Douyin’s scheduled release function allows users to automatically publish works at a scheduled time, which can better plan the release plan and increase the exposure and influence of the work. 1. How to set the scheduled time for publishing works on Douyin? To set a scheduled release time, first go to Douyin's personal homepage, find the "+" button in the upper right corner, and click to enter the release page. There is a clock icon in the lower right corner of the publishing page. Click to enter the scheduled publishing interface. In the interface, you can choose the type of work you want to publish, including short videos, long videos, and live broadcasts. Next, you need to set a time for your work to be published. TikTok provides

Do Not Disturb Mode Not Working in iPhone: Fix Do Not Disturb Mode Not Working in iPhone: Fix Apr 24, 2024 pm 04:50 PM

Even answering calls in Do Not Disturb mode can be a very annoying experience. As the name suggests, Do Not Disturb mode turns off all incoming call notifications and alerts from emails, messages, etc. You can follow these solution sets to fix it. Fix 1 – Enable Focus Mode Enable focus mode on your phone. Step 1 – Swipe down from the top to access Control Center. Step 2 – Next, enable “Focus Mode” on your phone. Focus Mode enables Do Not Disturb mode on your phone. It won't cause any incoming call alerts to appear on your phone. Fix 2 – Change Focus Mode Settings If there are some issues in the focus mode settings, you should fix them. Step 1 – Open your iPhone settings window. Step 2 – Next, turn on the Focus mode settings

How to set the watermark in the middle on Weibo_How to set the watermark in the middle on Weibo How to set the watermark in the middle on Weibo_How to set the watermark in the middle on Weibo Mar 29, 2024 pm 03:31 PM

1. First enter Weibo, then click on me in the lower right corner and select [Customer Service]. 2. Then enter [Watermark] in the search box and select [Set Weibo Image Watermark]. 3. Then click [Link] in the interface. 4. Then click [Image Watermark Settings] in the newly opened window. 5. Finally, check [Picture Center] and click [Save].

How to set up scheduled publishing on Weibo_Tutorial on how to set up scheduled publishing on Weibo How to set up scheduled publishing on Weibo_Tutorial on how to set up scheduled publishing on Weibo Mar 29, 2024 pm 03:51 PM

1. Open the Weibo client, click the three little dots on the editing page, and then click Scheduled Post. 2. After clicking on scheduled posting, there will be a time option on the right side of the publishing time. Set the time, edit the article, and click on the yellow words in the lower right corner to schedule posting. 3. The mobile version of Weibo does not currently support scheduled publishing. This function can only be used on the PC client!

Where to set Douyin recommendations and selections Where to set Douyin recommendations and selections Mar 27, 2024 pm 05:06 PM

Where are the recommendations and selections on Douyin? In Douyin short videos, there are two categories: selection and recommendation. Most users don’t know how to set up recommendations and selections. Next is the Douyin tutorial that the editor brings to users. Audio recommendations and selected setting method tutorials, interested users come and take a look! Douyin usage tutorial Where to set up Douyin recommendations and selections 1. First open the Douyin short video APP and enter the main page, click on the [Me] area in the lower right corner and select [three horizontal lines] in the upper right corner; 2. Then on the right The function bar will expand, slide the page to select [Settings] at the bottom; 3. Then on the settings function page, find the [Personal Information Management] service; 4. Finally jump to the personal information management page, slide [Personalized Content Recommendations] 】The buttons on the back can be set.

How to set the countdown to grab tickets in Damai How to set the countdown to grab tickets in Damai Apr 01, 2024 pm 07:01 PM

When buying tickets on Damai.com, in order to ensure that the ticket purchase time can be accurately grasped, users can set a floating clock to grab tickets. The detailed setting method is below, let us learn together. How to bind the floating clock to Damai 1. Click to open the floating clock app on your phone to enter the interface, and click on the location where the flash sale check is set, as shown in the figure below: 2. After coming to the page of adding new records, click on Damai.com Copy the ticket purchase link page copied in. 3. Next, set the flash sale time and notification time below, turn on the switch button behind [Save to Calendar], and click [Save] below. 4. Click to turn on [Countdown], as shown in the figure below: 5. When the reminder time comes, click the [Start Picture-in-Picture] button below. 6. When the ticket purchase time comes

Join a new Xianxia adventure! 'Zhu Xian 2' 'Wuwei Test' pre-download is now available Join a new Xianxia adventure! 'Zhu Xian 2' 'Wuwei Test' pre-download is now available Apr 22, 2024 pm 12:50 PM

The "Inaction Test" of the new fantasy fairy MMORPG "Zhu Xian 2" will be launched on April 23. What kind of new fairy adventure story will happen in Zhu Xian Continent thousands of years after the original work? The Six Realm Immortal World, a full-time immortal academy, a free immortal life, and all kinds of fun in the immortal world are waiting for the immortal friends to explore in person! The "Wuwei Test" pre-download is now open. Fairy friends can go to the official website to download. You cannot log in to the game server before the server is launched. The activation code can be used after the pre-download and installation is completed. "Zhu Xian 2" "Inaction Test" opening hours: April 23 10:00 - May 6 23:59 The new fairy adventure chapter of the orthodox sequel to Zhu Xian "Zhu Xian 2" is based on the "Zhu Xian" novel as a blueprint. Based on the world view of the original work, the game background is set

How to set Douyin playback to automatically close? Why does the playback process automatically exit? How to set Douyin playback to automatically close? Why does the playback process automatically exit? Apr 01, 2024 pm 12:06 PM

Douyin is one of the most popular short video platforms today. While enjoying the fun of short videos, users also hope to have better control over their time. Recently, some users reported that Douyin would automatically close during playback, which troubled them very much. 1. How to set the Douyin playback to automatically turn off? 1. Check the Douyin version. Please make sure that the Douyin version you are using is the latest. Douyin will be updated regularly to fix known issues. If your version of TikTok is too old, it may automatically close. You can check and update TikTok in the App Store. 2. Check the mobile phone system version. The automatic shutdown of Douyin playback may also be related to the mobile phone system version. Please make sure your mobile phone system version is the latest. If the mobile phone system version is too old, it may cause Douyin to run unstable. you can

See all articles