麻辣堂|资源主站|开发论坛|在线手册
首页 Apache Linux Java MySQL 注册帮助 
PHP项目开发组是PHP开发资源网于2007组年建成立的项目开发团队,目前核心开发成员有27人, 项目协作成员8名.下设7个开发组,主要承接大/中型网站项目开发任务。

    由于开发任务较多,人员比较紧张,现面向社会招聘全职或者兼职开发人员,不管你是在校大学生,还是全职开发人员,以及SOHO都可以联系本站,我们可以长期合作,并为您带来丰厚的报酬。
  您现在的位置:PHP开发资源网 > 麻辣堂 > 详细资料
待解决
怎么回事啊?为什么不能上传文件??
悬赏分:20 - 2007年08月15日

初学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?>

<?=$UPLOADIMG?>
<?=$CLICKTOUPLOAD?>

<? /*== 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 "就不行了 为什么啊? 服务器是别人配置的,我不太懂,与这个有关吗?

提问者:njueagle   08-15 08:08
答复
路过。。。顺便帮顶:)
回答者:玉米づ冰冻可乐 - 瓦岗村民 8-22 09:10
我也来回答:
不管你有没有帮助我们,瓦岗寨8万村民将感谢你。。。。。

为防止灌水,您需要计算一道数学题: 答案:
39 + 77 = ? 请将计算结果填在上面

 
[]
©2007 PhpRes.COM