0

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");
}

}


}
?>

Edited by peter_budo: Keep it Organized - For easy readability, always wrap programming code within posts in [code] (code blocks)

4
Contributors
6
Replies
8
Views
7 Years
Discussion Span
Last Post by FlashCreations
0

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.

Edited by FlashCreations: n/a

0

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

0

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

0

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.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.