Hi everybody,
would you please tell me what's wrong with this code
that generates the following error:

Warning: fopen(C:\Documents and Settings\Sando\Desktop\boys.gif) [function.fopen]: failed to open stream: No such file or directory in /home/domain/public_html/webs/divisions/chek.php on line 108
data inserted without any picture

although it works fine and great @ localhost
MySQL Server 5.1
Appache 2.2
PHP 5.2.11

and as I said just great
but on the server 'BLUEHOST' I get that error

help please:

<?php session_start();
// if session is not set redirect the user
if(empty($_SESSION['u_name'])){
 header("Location:table.php");
}
include ("connect.php");
include ("function.php");

$agent=$_SESSION['u_name'];
$sql="SELECT * FROM tbl_user WHERE user_name='$agent'    ";
$result=mysql_query($sql);
$row=mysql_fetch_array($result);
$pri= $row['pri'];
If($pri ==1 || $pri ==3) {
GoTO("../log/cp.php");	
}

$host="localhost";
$username="name";
$password="pass";
$db_name="db";
$tbl_name="teachers2";
//////////////////////////////////////////////////////////////
mysql_connect("$host", "$username", "$password")or die("cannot connect server "); 
mysql_select_db("$db_name")or die("cannot select DB");
//////////////////////////////////////////////////////////////

$N_Teacher = $_POST['N_Teacher'];
$N_Email = $_POST['N_Email'];
$N_Teacher = addslashes($N_Teacher);
$N_Email = addslashes($N_Email);
$N_date=date("d-m-y H:i:s");
$agent=$_SESSION['u_name'];
$division=$_POST['division'];
$divisionID=$_POST['divisionID'];
$position=$_POST['position'];
$positionID=$_POST['positionID'];
$employee=$_POST['employee'];
$wordcomm=$_POST['wordcomm'];
$N_Telefon=$_POST['N_Telefon'];

if (empty($N_Teacher) || empty($N_Email))
{
bad();
}
else {
good();
}
////////////////////////////////////
function bad(){
echo "<center><font color='ff0000' font face='Tahoma' size='2'><b>Please fill in both name and email</B></font></center>";
$htmlheader=InCludePageHtml("template/header.html");
eval("echo stripslashes(\"$htmlheader\");");
GoTO("add.php");
}
//////////////////////////////////////////////////////////////
function good(){

$N_Teacher = $_POST['N_Teacher'];
$N_Email = $_POST['N_Email'];
$N_Teacher = addslashes($N_Teacher);
$N_Email = addslashes($N_Email);
$N_date=date("d-m-y H:i:s");
$agent=$_SESSION['u_name'];
$division=$_POST['division'];
$divisionID=$_POST['divisionID'];
$position=$_POST['position'];
$positionID=$_POST['positionID'];
$employee=$_POST['employee'];
$wordcomm=$_POST['wordcomm'];
$N_Telefon=$_POST['N_Telefon'];

$hndl=fopen($_REQUEST["imgfile"],"r"); 
$isize=sizeof($_REQUEST["imgfile"]); 

if (empty($hndl) ){
                        $hndl=fopen("temp.gif","r"); 
                         $imgdata=""; 
                        while(!feof($hndl)){   $imgdata.=fread($hndl,$isize); }
                         $imgdata=addslashes($imgdata); 

$sql="INSERT INTO teachers2(N_Teacher,N_Email,position,N_date,agent,division,divisionID,positionID,wordcomm,employee, N_Telefon,imgtype,pic)VALUES                                          ('$N_Teacher','$N_Email','$position','$N_date','$agent','$division','$divisionID','$positionID','$wordcomm','$employee','$N_Telefon','". $_REQUEST["imgtype"] ."','$imgdata')";

$result=mysql_query($sql);

if($result){
ECHO "<center><font color='088000' font face='Tahoma' size='2'><b> data inserted without any pictures </font></center></b>";
echo "<BR>";
$htmlfother=InCludePageHtml("template/fother.html");
eval("echo stripslashes(\"$htmlfother\");");
GoTO("Del_Edit.php");
}

else{
ECHO "<center><font color='ff0000' font face='Tahoma' size='2'><b>db error</font></center></b>";
echo "<BR>";
$htmlfother=InCludePageHtml("template/fother.html");
eval("echo stripslashes(\"$htmlfother\");");
GoTO("add.php");
}

}




else {
                 $hndl=fopen($_REQUEST["imgfile"],"r"); 
                 $isize=sizeof($_REQUEST["imgfile"]); 
                 $imgdata=""; 
                 while(!feof($hndl)){   $imgdata.=fread($hndl,$isize); }
                 $imgdata=addslashes($imgdata); 

$sql="INSERT INTO teachers2(N_Teacher,N_Email,position,N_date,agent,division,divisionID,positionID,wordcomm,employee, N_Telefon,imgtype,pic)VALUES                                          ('$N_Teacher','$N_Email','$position','$N_date','$agent','$division','$divisionID','$positionID','$wordcomm','$employee','$N_Telefon','". $_REQUEST["imgtype"] ."','$imgdata')";
$result=mysql_query($sql);

if($result){
ECHO "<center><font color='088000' font face='Tahoma' size='2'><b> all data  inserted </font></center></b>";
echo "<BR>";
$htmlfother=InCludePageHtml("template/fother.html");
eval("echo stripslashes(\"$htmlfother\");");
GoTO("Del_Edit.php");
}

else{
ECHO "<center><font color='ff0000' font face='Tahoma' size='2'><b>db issue -error </font></center></b>";
echo "<BR>";
$htmlfother=InCludePageHtml("template/fother.html");
eval("echo stripslashes(\"$htmlfother\");");
GoTO("add.php");
}

}


}
?>
Member Avatar for diafol

Yuk! Use code tags - can't read that.

The problem is that C:\Documents and Settings\Sando\Desktop\boys.gif is a file on your desktop. It works on localhost, because that file exists on your desktop. You need to upload the boys.gif file to Bluehost and change the line that opens that file.

EDIT (AFTER EXAMINING YOUR CODE FURTHER)
Just wondering, are you trying to upload a file. It seems to me like you are, and sadly, fopen will only work on the server. To understand how to upload files to a PHP script, read this article by Tizag.

Well, Thank you FlashCreations for answering!!!

I am not trying to upload to the server rather to insert into a db
but after reading the file name and size from the tmp folder on the server.

otherwise, I could have used move_uploaded_file($_FILES["file"]["tmp_name"], to store on the server ...

please help

So what exactly do you want? Insert the file name into a db?

try moving that directory somewhere below or in public_html (doc root).
Then access it there.

If you are trying to create an uploader, look into PHP file handling and uploading on W3Schools to learn more. If not, simply follow my and JRM's advice: upload the image to your web root (or a folder inside of it) and then change your fopen so that it reflects the new location of the file.

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.