初学php,改了一个文件上传的程序,怎么调试都不正确
望各位大虾帮帮忙,
代码:
<?php
include_once "main.php";
include_once "connect.php";
include_once "configuration.inc.php";
$user_id=$_SESSION[user_id];
$q1 = "select image from job_info where user_id = \"$user_id\" ";
$r1 = mysql_query($q1) or die(mysql_error());
$a1 = mysql_fetch_array($r1);
?>
<?=$UPLOADIMG?>
<?
if ($_SERVER["REQUEST_METHOD"] == "POST")
{
/* SUBMITTED INFORMATION - use what you need
* temporary filename (pointer): $imgfile
* original filename : $imgfile_name
* size of uploaded file : $imgfile_size
* mime-type of uploaded file : $imgfile_type
*/
/*== upload directory where the file will be stored
relative to where script is run ==*/
$uploaddir = "./images";
$imgfile=$_FILES['imgfile'];
$imgfile_name=$_FILES['imgfile']['name'];
$imgfile_size=$_FILES['imgfile']['size'];
$imgfile_type=$_FILES['imgfile']['type'];
/*== get file extension (fn at bottom of script) ==*/
/*== checks to see if image file, if not do not allow upload ==*/
$pext = getFileExtension($_FILES['imgfile']['name']);
$pext = strtolower($pext);
if (($pext != "jpg") && ($pext != "jpeg") && ($pext != "gif"))
{
print "ERROR
Image Extension Unknown.
";
print "Please upload only a JPEG or GIF image with the extension .gif , .jpg or .jpeg ONLY
";
print "The file you uploaded had the following extension: $pext
\n";
/*== delete uploaded file ==*/
exit();
}
/*== setup final file location and name ==*/
/*== change spaces to underscores in filename ==*/
$rand_numb = md5(uniqid(microtime())); //generate random name u can change this to rand(1,99999); if u want make shorter name
$neu_name = "$rand_numb"."$imgfile_name";
$final_filename = str_replace(" ", "_", $neu_name);
$newfile = $uploaddir . "/$final_filename";
echo $newfile;
/*== do extra security check to prevent malicious abuse==*/
if (is_uploaded_file($imgfile))
{
echo "ok";
/*== move file to proper directory ==*/
if (!copy("$imgfile","$newfile"))
{
/*== if an error occurs the file could not
be written, read or possibly does not exist ==*/
print "Error Uploading File.";
exit();
}
}
/*== delete the temporary uploaded file ==*/
echo "
This is the image you upload :

If you want to replace it just upload another image .
Go Back";
/*== DO WHATEVER ELSE YOU WANT
SUCH AS INSERT DATA INTO A DATABASE ==*/
if (is_uploaded_file($imgfile))
{
$qup = "update job_info set image = \"$newfile\" where user_id = \"$user_id\" ";
$rup = mysql_query($qup) or die(mysql_error());
include "footer.php";
exit();
}
}
?>
Upload your Picture !
<?=$WARNINGUPLOAD?>
<?
/*== FUNCTIONS ==*/
function getFileExtension($str) {
$i = strrpos($str,".");
if (!$i) { return ""; }
$l = strlen($str) - $i;
$ext = substr($str,$i+1,$l);
return $ext;
}
include_once('footer.php');
?>
另外,执行到"echo $newfile"都是正确的但到"echo ok "就不行了
为什么啊?
服务器是别人配置的,我不太懂,与这个有关吗?