如何上传具有变量名称的文件

时间:2012-10-23 11:03:34

标签: php

我上传文件有问题,  我正在使用这段代码...... 并收到此错误,

我的文件夹名称是garment_images

 <?php
    $pid          = mysql_insert_id();
    $folder       = $_post['catagory'];
    //insert images into folder
    $product_name = "$pid.jpg";
    move_uploaded_file($_FILES['productImage']['tmp_name'], "$folder._images" / $product_name);
    echo "<h1>Your product successfully added <br /> Plese wait....</h1>";
    header("refresh:3; url='inventory.php'");
    exit();
    ?>
    <form method='post' action='index.php'>
    <input type="file" name="productImage" />
<input type="text" name="catagory" />
    </form>

2 个答案:

答案 0 :(得分:2)

纠正了几个错误,这是你的代码:

<?php
$pid          = mysql_insert_id();
$folder       = $_POST['category']; // assuming you had category other wise, no correction
//insert images into folder
$product_name = "$pid.jpg";
move_uploaded_file($_FILES['productImage']['tmp_name'], "$table._images/ $product_name"); // string concat mistake
echo "<h1>Your product successfully added <br /> Please wait....</h1>";
echo "<meta http-equiv='refresh' content='3; inventory.php' />";// use meta tag to redirect instead of header which will give you headers already sent error
// exit(); // if not commented out, the below form will never be shown!
?>
<form method='post' action='index.php'>
<input type="file" name="productImage" />
</form>

如果您开始使用PHP,我强烈建议您在编码时使用IDE,并需要帮助。

答案 1 :(得分:1)

你写'刷新',正确是'刷新'。