•
•
•
•
What is DaniWeb IT Discussion Community?
You're currently browsing the PHP section within the Web Development category of DaniWeb, a massive community of 426,634 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 1,592 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our PHP advertiser: Lunarpages PHP Web Hosting
Views: 1050 | Replies: 4
![]() |
•
•
Join Date: Aug 2007
Posts: 21
Reputation:
Rep Power: 2
Solved Threads: 0
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">
<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..
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">
<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..
You said that your code output is:
And it's pretty obvious that the:
function would print this output.
What is your actual problem?
!!!
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);
What is your actual problem?
!!!
<?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.
<?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.
•
•
Join Date: Aug 2007
Posts: 21
Reputation:
Rep Power: 2
Solved Threads: 0
•
•
•
•
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:
function would print this output.print_r($_FILES);
What is your actual problem?
!!!
My problem is that it is not uploading any images
![]() |
•
•
•
•
•
•
•
•
DaniWeb PHP Marketplace
•
•
•
•
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
- Image UPLOAD concept (PHP)
- Coldfusion image upload w. javascript thumbnail preview (ColdFusion)
- Image Upload/Acquisition (Web Developers' Lounge)
- Upload problem of large files in Win 2003 (Windows NT / 2000 / XP / 2003)
- File upload problem (PHP)
- Dreamweaver Image Moving Problem (Site Layout and Usability)
- image retrieval problem (PHP)
- Flash - loaded swf image quality problems (Graphics and Multimedia)
- problem up loading photo files (Web Browsers)
Other Threads in the PHP Forum
- Previous Thread: Please help debug my code
- Next Thread: how to send sms from web site to mobile


Linear Mode