move_uploaded_file not working, yet no errors generated

I posted this on Stack Overflow, but I’ve gotten minimal response there.

I have a file upload page, and I have gone through the code and inserted debugging lines incrementally, line-by-line, to try to find the cause of this problem. The problem occurs somewhere in this block of code:

[php] $tmp_name = $_FILES[‘image_large’][‘tmp_name’];
$name = getcwd().DIRECTORY_SEPARATOR.$_FILES[‘image_large’][‘name’];
$success = move_uploaded_file($tmp_name,$name);
$errormsg = “

source: {$tmp_name}

destination: {$name}

$errormsg .= “

did it upload: {$success}


This $errormsg gets printed on the page, and displays the following result:

[code]source: C:\xampp\tmp\php4A14.tmp

destination: C:\xampp\htdocs\photos\fingerlakes1.jpg

did it upload: 1[/code]

That destination is the correct, intended location for the file to go. Yet when I check, there is no file “C:\xampp\htdocs\photos\fingerlakes1.jpg” produced, even though the debugging results seem to suggest the computer is convinced it performed the task successfully.

I have also made sure the folder has write permissions enabled (I’m on Windows 7), although I think that if that were the cause, $success would not have evaluated as true. I should also mention that there is another block of code very similar to the above for $_FILES[‘image_thumb’], but it is commented out for now.

I also tried using print_r($_FILES) to check everything, and it returned:

Array ( [image_large] => Array ( [name] => fingerlakes1.jpg [type] => image/jpeg [tmp_name] => C:\xampp\tmp\php5694.tmp [error] => 0 [size] => 497376 ) [image_thumb] => Array ( [name] => fingerlakes1.jpg [type] => image/jpeg [tmp_name] => C:\xampp\tmp\php5695.tmp [error] => 0 [size] => 26228 ) )

So it appears that the files are uploaded correctly to the tmp folder, at least.

Further information in case it helps: I am using XAMPP, with the XAMPP Control Panel running in Administrator Mode. I am only local-testing right now (in other words, the file upload should merely copy the file from one part of my computer to another). I went into the destination folders “photos” and “thumbnails” and did right-click -> properties -> Security, and made sure that every single user listed has write access, just to make sure. There is only one account on this computer, but it listed the account name twice as user and administrator, plus SYSTEM and one other one I forget. But I gave them all write access to be on the safe side.

In addition, I have noticed that every folder on my C drive, when I right-click it and choose Properties, has the box “read-only” checked… every single folder. Yet I can save and write files just fine other than this issue, and unchecking that box only lasts until I close the Properties box; when I reopen it the read-only box is checked again. I doubt this is the problem since it’s not stopping me from saving other files I am working on.

Regarding the last paragraph, I actually am starting to think the problem I have has nothing to do with the php code, and is more of a Windows issue. I neglected to mention that the site files were originally on a previous hard drive (which had to be replaced due to failure), and the upload form was working correctly there, and I haven’t changed the upload form code since then. The main difference was that back then I was manually putting the file into the intended destination folder, and using the file upload form was basically overwriting the file with itself. There was a point in doing this because the file upload form contained other fields besides the file, and that needed to get written to a MySQL database. The code to do the database work follows shortly after the first code block at the top of the thread. The database writing worked fine on the old hard drive, but is getting interfered with by the file upload problem on the new one. Some data gets written, to the wrong place (fortunately it’s always the same place so I can fix it every time this error happens while trying to solve the problem), and other data isn’t getting written at all.

So I am going to try a couple solutions. First, I am going to try and do exactly what I did on the previous drive, which is to manually put the file into the intended destination, use the file upload to overwrite it with itself, and test whether or not it is then correctly inputting the MySQL information.

Second, I am going to try uploading the database and administrative site files (everything posted in this thread refers to admin-side files that require log-in to access), and test if, in fact, the file upload will work fine on the web, and if the problem can therefore be proven to be an issue local to my computer and not a problem with the code itself.

Sponsor our Newsletter | Privacy Policy | Terms of Service