Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.3k views
in Technique[技术] by (71.8m points)

php - Warning: File upload error - unable to create a temporary file in Unknown on line 0

Am getting the following error everytime I try to upload a file .

"Warning: File upload error - unable to create a temporary file in Unknown on line 0"

Here is my HTML form,

<form action="./inventory_list.php" enctype="multipart/form-data" name="myForm" id="myForm" method="post">
<table width="625" border="1" cellpadding="5">
  <tr>
    <td width="84">Product Name</td>
    <td width="399"><input type="text" name="product_name" id="product_name"></td>
  </tr>
  <tr>
    <td>Product Price</td>
    <td><label for="textfield2">Rs:</label>
      <input type="text" name="price" id="price"></td>
  </tr>
  <tr>
    <td>Category</td>
    <td><select name="category" id="category">
        <option value="" selected="selected"></option>
        <option value="Bedroom ">Bedroom </option>
        <option value="Living">Living room</option>
        <option value="Dining">Dining</option>
      </select></td>
  </tr>
  <tr>
    <td>Sub - Category</td>
    <td><select name="subcategory" id="subcategory">
        <option value="" selected="selected"></option>
        <option value="dinet">Dining tables</option>
        <option value="shoe">shoe racks</option>
        <option value="wardrobe">wardrobes</option>
        <option value="sofa">sofa</option>
      </select></td>
  </tr>
  <tr>
    <td>Product Details</td>
    <td><textarea name="details" cols="50" rows="10" id="details"></textarea></td>
  </tr>
  <tr>
    <td>Product Image</td>
    <td><label>
        <input type="file" name="fileField" id="fileField"/>
      </label></td>
  </tr>
  <tr>
    <td>&nbsp;</td>
    <td><input type="submit" name="button" id="button" value="Add this Item now"></td>
  </tr>
</table>
</br>
</form>

Here is my PHP code ,

if(isset($_POST["product_name"]))
{
    $product_name = mysql_real_escape_string($_POST["product_name"]);
    $price= mysql_real_escape_string($_POST["price"]);
    $category= mysql_real_escape_string($_POST["category"]);
    $subcategory= mysql_real_escape_string($_POST["subcategory"]);
    $details= mysql_real_escape_string($_POST["details"]);

    //see if duplicate product exists
    $sql = mysql_query("select id from products where product_name='$product_name' limit 1");
    $product_match = mysql_num_rows($sql);   //count the output

    if($product_match>0)
    {
        echo "The product name already exists";
        exit();
    }
    $sql= mysql_query("INSERT INTO `mystore`.`products` (`product_name`, `price`, `details`, `category`, `subcategory`, `date_added`) VALUES ( '$product_name', '$price', '$details', '$category', '$subcategory', now());")or die(mysql_error());
    $pid = mysql_insert_id();
    $newname = "$pid.jpg";

    move_uploaded_file($_FILES['fileField']['tmp_name'],'../inventory_images/$newname');
}

Am trying to upload on localhost , Test Server:XAMPP , OS : MAC 10.8

Am stuck on this from a long time , I tried a lot of things but nothing is working .

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

In a terminal type :

chmod -R 777 /your/upload/folder

you can know the folder where your php uploads files by executing this code :

$tmp_dir = ini_get('upload_tmp_dir') ? ini_get('upload_tmp_dir') : sys_get_temp_dir();
die($tmp_dir);

In my case I get /var/... so when I sett 777 permission I get no error.

Edit

Setting 777 to /var is dangerous so you have to set it only to the folder where php uploads the file (which you can get buy the code above).


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...