Lessur Posted July 21, 2006 Share Posted July 21, 2006 Ok, I have this code:upload.php:[code]$max_filesize = 5000000;$max_imagesize = 20480;$filename=rand(500,2000).$_FILES['file']['name'];$small_image=rand(500,2000).$_FILES['file']['name'];$smallimagepath = "/small_images";...elseif ($_FILES['file']['name'] == "") {echo "Field flash file left blank <a href='?'>Go back?</a>";}elseif ($_FILES['file']['size'] > $max_filesize){echo "Error! flash file must not be bigger than 5 MB <a href='?'>Go back?</a>";}...elseif(file_exists($upload.$filename)){echo "Error! File already exists on server, rename and try again. <a href='?'>Go back?</a>";}elseif ($_FILES['small_image']['size'] > $max_imagesize){echo "Error 50x50 image must not be bigger than 20k <a href='?'>Go back?</a>";}elseif(file_exists($upload.$small_image)){echo "Error! 50x50 image already exists on server, rename and try again. <a href='?'>Go back?</a>";}else{$upload = dirname(__FILE__)."/uploads/";copy($_FILES['file']['tmp_name'],$upload.$filename) or die("<br>Error! Couldn't upload file! <a href='?'>Go back?</a>");$size=$_FILES['file']['size'];$upload = dirname($smallimagepath)copy($_FILES['small_image']['tmp_name'],$upload.$small_image) or die("<br>Error! Couldn't upload 50x50 Image! <a href='?'>Go back?</a>");.....<input type="file" name="file">....<input type="file" name="small_image"> [/code]What I want this to do, is upload the file in the small_image box to directory ' small_images ' and for the ' file ' to upload to uploads. I also want them to submit their filepath to the database.What it is doing instaed of this is making 2 copies of ' file ' and putting 1 in both ' uploads ' and ' small images '. It is also submitting the file path to the mysql database under both 'file' and ' small_image 'How can I stop this from happening? Quote Link to comment Share on other sites More sharing options...
spyke01 Posted July 21, 2006 Share Posted July 21, 2006 this is one of the problem[code]$filename=rand(500,2000).$_FILES['file']['name'];$small_image=rand(500,2000).$_FILES['file']['name'];[/code]should be[code]$filename=rand(500,2000).$_FILES['file']['name'];$small_image=rand(500,2000).$_FILES['small_image']['name'];[/code]because of the name on the input field Quote Link to comment Share on other sites More sharing options...
Lessur Posted July 21, 2006 Author Share Posted July 21, 2006 Ok, I fixed that and did this:[code]$upload2 = dirname($smallimagepath);copy($_FILES['small_image']['tmp_name'],$upload2.$small_image) or die("<br>Error! Couldn't upload 50x50 Image! <a href='?'>Go back?</a>"); [/code]But I am getting "Error! Couldn't upload 50x50 Image!" as an error. Hmm. Quote Link to comment Share on other sites More sharing options...
Lessur Posted July 21, 2006 Author Share Posted July 21, 2006 hmmn.... Quote Link to comment Share on other sites More sharing options...
ryanlwh Posted July 21, 2006 Share Posted July 21, 2006 try to print out $_FILES['small_image']['error']. see what the error code is. maybe the file exceeded the upload max filesize. Quote Link to comment Share on other sites More sharing options...
Lessur Posted August 6, 2006 Author Share Posted August 6, 2006 Ok, I have come back to this topic becasue I was out of town. The image did not exceed the max filesize. I still don't know how to fix this. I have tried all the above. But when I clikc submit I get:"Error! Couldn't upload 50x50 Image!"Which is this line:[code]copy($_FILES['small_image']['tmp_name'],$upload2.$small_image) or die("<br>Error! Couldn't upload 50x50 Image! <a href='?'>Go back?</a>");[/code]Help? Quote Link to comment Share on other sites More sharing options...
Lessur Posted August 6, 2006 Author Share Posted August 6, 2006 Oh, for the reg file upload (that works) I have this code:$upload = dirname(__FILE__)."/uploads/";But for the small image one I have:$upload2 = dirname($smallimagepath);Instead should I have:$upload2 = dirname(__FILE__)."/small_images/"; ?Or what does __FILE__ do? Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.