![]() |
Uploading File Problem
Can anybody see where I'm going wrong with this file upload script?
It works fine for some files but the odd one it will redirect me to "create_gallery.php?msg=e" even though it's a perfectly normal image file. PHP Code:
|
You have two possibilities. ?msg=e shows up under the possible circumstances:
1) Your $create_gallery insert fails for whatever reason. check your mysql_error to see if anything is being output on the one that fails. (if it does) What is the second else that redirects to ?msg=e part of? IE what is the original if statement. Identation mate!! |
*oops double post*
|
Ok, the 2nd one is from this statement, correct?
if(move_uploaded_file($_FILES['uploadedfile']['tmp_name'], $target_path)) { Any reason (like load balancing) that the temp file wouldn't exist, or a problem with the target path in those particular circumstances? Off topic to your original post, does this get the type of file? I have never seen this before, never thought about using a command to get it (and far more reliable then the PHP mime_type I assume: $szMimetype = shell_exec(escapeshellcmd ("file -bi ".$FILES['uploadedfile']['tmp_name'])); cool! |
My problem is I wrote this about a month ago and couldn't get it to work properly, then I added and edited bit so much I cant remember what I ended up with *!*
I was hoping someone might be able to see something I didn't but it looks like I'll just have to rewrite the whole thing from scratch. Does anybody have a good, working image upload script I can look at? I wont copy it exactly, I just want to see how you check mime/file types etc. |
That's why I like as-I-go debugging. When I'm coding, depending on how into a certain section I am, I'll constantly flip from my editor to the browser to run the script and see how things are going. That way I can catch problems before I've gone so far that I have to backtrace twice as long to find a typo.
My other favourite debugging practice is to flex my muskles, load a clip into the chamber, through on some gangsta rap, and starting sprinkling die() statements throughout my code. Then I can run it till it dies, see if it works, go to the next die... I've even found some notices pop up from time to time when I do that, that I would've never seen otherwise. I don't know if this'll help any, and it's part of a script I did a while back so I haven't optimized it any time lately, but you can check out the image upload and thumbnail functions I use in my user authentication system here: http://pastebin.com/m253910de -m |
Thanks for that :-)
The only part I think I need is the part where you check for a valid file and mime type. My script seems to work fine apart from those two things. I'll work on this later today and post here if I get any more problems. |
| All times are GMT. The time now is 07:44 PM. |
Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0