English 中文(简体)
move_ uploaed_file 文件在两次调用时无法工作
原标题:move_uploaded_file file not work when it will call two time
  • 时间:2012-05-23 04:24:47
  •  标签:
  • php

我有一个要上传 php 文件的函数, 例如 :

function upload_file($folder,$name)
{
$dest = "../product/". $folder."/". $name;
$src       = $_FILES[ image ][ tmp_name ];
if (move_uploaded_file($src, $dest)) {
    } else {
        echo "<script> alert( " . $src . " );
            window.history.go(-1); </script>
";
        exit();
    }
}

whene i call function only one time like upload_file( small , abc.jpg ) it works fine but i have call two time like:

upload_file( small , abc.jpg )
upload_file( big , abc.jpg )

它在二文件夹上没有工作, 大

有什么解决办法吗?

最佳回答

move_uploaded_file has moved to the first destination. So, the solution is get the first destination path, and copy with it for the other.

这将有很多解决方案。其中之一,将参数转换成数组并循环。

<?php
$filesDes = array(
           array( folder => small , name => abc.jpg ),
           array( folder => big , name => abc.jpg ));

function upload_file($arrayfile)
{
    $firstfile = null;
    foreach($arrayfile as $val)
    {
        $dest = "../product/". $val[ folder ]."/". $val[ name ];
        if(!isset($firstfile))
        {
            $firstfile = $dest;
            $src       = $_FILES[ image ][ tmp_name ];
            if (!move_uploaded_file($src, $dest)) {
               echo "<script> alert( " . $src . " );
               window.history.go(-1); </script>
";
               exit();
            }
        }
    }
    else
    {
        if(!copy ( $firstfile , $dest ))
        {
           echo "<script> alert( " . $dest . " );
           window.history.go(-1); </script>
";
           exit();
        }
    }
}
upload_file($filesDes)
问题回答

暂无回答




相关问题
Brute-force/DoS prevention in PHP [closed]

I am trying to write a script to prevent brute-force login attempts in a website I m building. The logic goes something like this: User sends login information. Check if username and password is ...

please can anyone check this while loop and if condition

<?php $con=mysql_connect("localhost","mts","mts"); if(!con) { die( unable to connect . mysql_error()); } mysql_select_db("mts",$con); /* date_default_timezone_set ("Asia/Calcutta"); $date = ...

定值美元

如何确认来自正确来源的数字。

Generating a drop down list of timezones with PHP

Most sites need some way to show the dates on the site in the users preferred timezone. Below are two lists that I found and then one method using the built in PHP DateTime class in PHP 5. I need ...

Text as watermarking in PHP

I want to create text as a watermark for an image. the water mark should have the following properties front: Impact color: white opacity: 31% Font style: regular, bold Bevel and Emboss size: 30 ...

How does php cast boolean variables?

How does php cast boolean variables? I was trying to save a boolean value to an array: $result["Users"]["is_login"] = true; but when I use debug the is_login value is blank. and when I do ...

热门标签