I have written the following image upload code:

image_upload.html:

<html>
<head>
</head>
<body>
<form method="post" action="check_image.php" enctype="multipart/form-data">
<table border="0" cellpadding="5">
<tr>
   <td>Image title or caption</td>
     <td><input name="image_caption" type="text" id="image_caption" size="55" maxlength="255" /></td>
       </tr>
       <tr>
       <td>Your user name:</td>
          <td><input name="image_username" type="text" id="image_username" size="55" maxlength="255" /></td>
          </tr>
        <tr>
        <td>Upload image:</td>
        <input type="hidden" name="MAX_FILE_SIZE" value="2000000" />
         <td><input name="image_filename" type="file" id="image_filename"></td>
         </tr>
         </table>
         <br>

<p align="center"><input type="submit" name="Submit" value="Submit">
&nbsp;<input type="reset" name="Submit2" value="Clear Form">
</p>
</form>
</body>
</html>

check_image.php:

<? 

include('../functions.php');
mysql_connect("loaclhost","username","password")
or die("Failure to communicate");
mysql_select_db("db")
or die("Could not connect to Database");

$image_caption = $_POST['image_caption'];
$image_username = $_POST['image_username'];
$image_caption = $_FILES['image_filename']['name'];
$today = date("Y-m-d");
$ImageDir = "D:/uploads/";
$ImageName = $ImageDir . $image_tempname;
if(move_uploaded_file($_FILES['image_filename']['tmpname'],$ImageName)){
      list($width, $height, $type, $attr) = getimagesize($ImageName);

   switch($type){
       case 1:
        $ext = ".gif";
        break;

       case 2:
        $ext = ".jpg";
        break;

       case 3:
        $ext = ".png";
        break;

       default :
         echo "Sorry";}}
         print_r($_FILES);


?>  

And its giving the following output:

Array ( [image_filename] => Array ( [name] => little-baby-monkeys.jpg [type] => image/pjpeg [tmp_name] => C:\PHP\uploadtemp\php1839.tmp [error] => 0 [size] => 105075 ) )   

Can anyone please help me? its urgent..

Recommended Answers

All 4 Replies

You said that your code output is:

Array ( [image_filename] => Array ( [name] => little-baby-monkeys.jpg [type] => image/pjpeg [tmp_name] => C:\PHP\uploadtemp\php1839.tmp [error] => 0 [size] => 105075 ) )

And it's pretty obvious that the:

print_r($_FILES);

function would print this output.
What is your actual problem?


!!!

Member Avatar for fatihpiristine
<?php include("dbcon.php"); ?> //db settings here
<?php
//--------------------------------------------------------------------------------
$path = "D:\websites\mysite.com\Uploads\\";
$web = "../uploads/";
$nopic = "../images/nopic.jpg";
$ad = "add_item";
$no = "1";
$page = $ad.$no;
//--------------------------------------------------------------------------------
$isim = $_REQUEST['NewsID'];  // isim stands for renaming. 
$tip = $_FILES[img1][type];  // tip = type
$size = $_FILES[img1][size];  
//--------------------------------------------------------------------------------
$Edit = $_COOKIE['Edit'.$no];
if($Edit != "")
{
$GetID = "select * from news where NewsID='" . $isim . "'";
$FindID=mysql_query($GetID);
while($WriteID = mysql_fetch_array($FindID))
{
    if($WriteID['Resim'.$no] != "")
    {
    setcookie('Edit'.$no,'');
    $dosya = $WriteID['Resim'.$no];
    }
    else
    {
    setcookie('Edit'.$no,'');
    $dosya = $nopic;
    }
}
}
//--------------------------------------------------------------------------------
elseif($size >= 150000)
{
    $dosya = $nopic;
    //Temizle
    $sil1 = $isim."_".$no.".jpg";
    $sil2 = $isim."_".$no.".png";
    $sil3 = $isim."_".$no.".gif";
    @unlink($path.$sil1);
    @unlink($path.$sil2);
    @unlink($path.$sil3);
    $uyari = "<small>Max 150Kb</small>";
}
//--------------------------------------------------------------------------------
elseif($tip == "image/jpeg" || $tip == "image/pjpeg")
{
    $dosya = $isim."_".$no.".jpg";
    //Temizle
    $sil1 = $isim."_".$no.".jpg";
    $sil2 = $isim."_".$no.".png";
    $sil3 = $isim."_".$no.".gif";
    @unlink($path.$sil1);
    @unlink($path.$sil2);
    @unlink($path.$sil3);
    // Veritabanina Yaz
    $query = "update news set Resim". $no ." ='" . $dosya . "' where NewsID=". $isim ."";
    mysql_query($query) or die(mysql_error());
    //Kopyala
    @copy($_FILES[img1][tmp_name],$path.$dosya);

}

i wrote this one last year and still use it... dont say pls, it doesnt work.

You said that your code output is:

Array ( [image_filename] => Array ( [name] => little-baby-monkeys.jpg [type] => image/pjpeg [tmp_name] => C:\PHP\uploadtemp\php1839.tmp [error] => 0 [size] => 105075 ) )

And it's pretty obvious that the:

print_r($_FILES);

function would print this output.
What is your actual problem?


!!!

My problem is that it is not uploading any images

Did you find the answer to your problem? i have the same error and i haven't find any solution please help.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.