There's no such thing as a stupid question, but they're the easiest to answer.
JoinTour
Login
 
Tag Cloud
acer black screen blue screen boot bsod computer connection crash css dell display driver drivers email error excel explorer firefox firefox 3 game hard drive internet internet explorer itunes laptop lcd linux malware network networking nvidia outlook outlook 2003 outlook express partition printer problem ram router slow sound sprtcmd.exe trojan usb video virus vista windows windows xp wireless
Web Design & Development
Search
Search in:
 
Advanced Search
Tech Support Guy Forums > Internet & Networking > Web Design & Development >
PHP won't replace .doc with another .doc


HELLO AND WELCOME! Before you can post your question, you'll have to register -- it's completely free! Click here to join today! We highly recommend that you print a copy of our Guide for New Members. Enjoy!

Closed Thread
 
Thread Tools
DrP's Avatar
DrP DrP is offline
Senior Member with 481 posts.
 
Join Date: Jul 2005
Location: UK
Experience: What's a compoota?
12-Sep-2006, 01:09 PM #1
PHP won't replace .doc with another .doc
I have this form for uploading a file and updating the database containing the filename.
For some reason, it won't upload the file if it is a Word .DOC.

This works:
Swap .DOC for JPG
Swap .JPG for another JPG
Swap .JPG for .DOC

but if I try and swap .DOC for another .DOC when I try and view the file it is still the old one!
For some reason PHP isn't uploading and renaming a file if it is a .DOC and the old file is a .DOC. If the old file is any other extension it works!

How on earth do I solve this?

Oh, and it works fine running on my computer at home but not on the actual server hosting it.
__________________
Clive
covert215's Avatar
Account Disabled with 2,651 posts.
 
Join Date: Apr 2006
Experience: Web Designer
12-Sep-2006, 03:26 PM #2
maybe your server doesn't support .doc filetypes?

i doubt that is it...just throwing something out there
brendandonhu's Avatar
Distinguished Member with 15,988 posts.
 
Join Date: Jul 2002
Location: Ann Arbor, MI
Experience: Advanced
12-Sep-2006, 04:27 PM #3
Can you post your code?
Maybe the permissions on the files are set differently as well.
DrP's Avatar
DrP DrP is offline
Senior Member with 481 posts.
 
Join Date: Jul 2005
Location: UK
Experience: What's a compoota?
12-Sep-2006, 04:43 PM #4
I just can't understand this. I thought the problem had gone away earlier but it is back, though not all the time.
I've just uploaded the file about 8 times, having made small changes to the .doc document. Only 3 of those times was it uploaded properly. The rest, when I opened or downloaded it from the website it remained unchanged (ie the old version).

Here's the code which processes the updating of the file:
$plan_datefor = trim($plan_date . " " . $plan_month);
if (!empty($plan_datefor)) {
$plan_datefor = "Monday " . $plan_datefor;
$update1 = "UPDATE planning SET datefor = '$plan_datefor' WHERE id = $id";
$result1 = mysql_query($update1) or die(mysql_error());
}
if (!empty($plan_topic)) {
$update3 = "UPDATE planning SET topic = '$plan_topic' WHERE id = $id";
$result3 = mysql_query($update3) or die(mysql_error());
}
$error = 0;
$file_tempname = $_FILES['plan_upload']['name'];
$extension = strchr($file_tempname, '.');
if (!empty($file_tempname)) {
if (!empty($file_tempname) && $extension != ".jpg" && $extension != ".gif" && $extension != ".png" && $extension != ".doc"
&& $extension != ".xls" && $extension != ".txt" && $extension != ".notebook" && $extension != "xbk"
&& $extension != ".pdf" && $extension != ".ppt" && $extension != ".zip" && $extension != ".rar"
&& $extension != ".exe" && $extension != ".html" && $extension != ".swf" && $extension !=".txt") {
$error = 5;
$error_message = "The file you have chosen is of illegal file type. Please choose another.";
}
if ($error == 0) {
echo "error = 0";
$sql = "SELECT * FROM planning WHERE id = '$id'";
$result = mysql_query($sql) or die(mysql_error());
$row = mysql_fetch_array($result);
extract($row);
unlink($upload);
$filedir = "planning/";
$file_tempname = $filedir . $_FILES['plan_upload']['name'];
move_uploaded_file($_FILES['plan_upload']['tmp_name'], $file_tempname);
$fileid = $id;
$newfilename = $filedir . $fileid . $extension;
rename($file_tempname, $newfilename);
$update2 = "UPDATE planning SET upload = '$newfilename' WHERE id = $id";
$result2 = mysql_query($update2) or die(mysql_error());
$redirect = "planning.php";
header("Refresh: 1.5; URL=$redirect");
include "includes/header.inc.php";
echo "<p>Plan updated successfully.</p>";
echo "<p>Redirecting...</p>";
include "includes/footer.inc.php";

and the test statement echo "error = 0" is being shown.
__________________
Clive
brendandonhu's Avatar
Distinguished Member with 15,988 posts.
 
Join Date: Jul 2002
Location: Ann Arbor, MI
Experience: Advanced
12-Sep-2006, 05:13 PM #5
Are all of the files named as .doc and not .DOC?
DrP's Avatar
DrP DrP is offline
Senior Member with 481 posts.
 
Join Date: Jul 2005
Location: UK
Experience: What's a compoota?
13-Sep-2006, 01:40 AM #6
Yes, they are all .doc.
brendandonhu's Avatar
Distinguished Member with 15,988 posts.
 
Join Date: Jul 2002
Location: Ann Arbor, MI
Experience: Advanced
13-Sep-2006, 04:02 PM #7
You should check whether move_uploaded_file is returning true or false, that will tell you whether the file is being copied.
DrP's Avatar
DrP DrP is offline
Senior Member with 481 posts.
 
Join Date: Jul 2005
Location: UK
Experience: What's a compoota?
13-Sep-2006, 05:45 PM #8
I'll have to wait until it happens again. It hasn't happened today.
Thanks anyway.
DrP's Avatar
DrP DrP is offline
Senior Member with 481 posts.
 
Join Date: Jul 2005
Location: UK
Experience: What's a compoota?
14-Sep-2006, 01:07 PM #9
It only seems to be happening on my lap-top. If I open the updated file it is the old file, yet if I reight click Save As then it is the new file which is saved.I think it is just my browser.
Closed Thread

THIS THREAD HAS EXPIRED.
Are you having the same problem? We have volunteers ready to answer your question, but first you'll have to join for free. Need help getting started? Check out our Welcome Guide.


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
WELCOME TO TECH SUPPORT GUY! Are you looking for the solution to your computer problem? Join our site today to ask your question -- for free! Our site is run completely by volunteers who help people like you solve computer problems. See our Welcome Guide to get started.



Thread Tools


You Are Using:
Server ID
Advertisements do not imply our endorsement of that product or service.
All times are GMT -4. The time now is 08:59 PM.
Copyright © 1996 - 2008 TechGuy, Inc. All rights reserved.
Powered by vBulletin, Copyright © 2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0
Powered by Cermak Technologies, Inc.