The Little Guy Posted June 22, 2007 Share Posted June 22, 2007 Why doesn't this upload the image? The folder exists, and I am using enctype="multipart/form-data" <?php include "../../includes/include.php"; if(!isLogged()){ header("Location: ../friends/"); exit; } foreach ($_FILES["image"]["error"] as $key => $error) { if ($error == UPLOAD_ERR_OK) { $tmp_name = $_FILES["image"]["tmp_name"][$key]; # Create a new file name $string = "abcdefghijklmnopqrstuvwxyz0123456789"; for($i=0;$i<45;$i++){ $pos = rand(0,36); $str .= $string{$pos}; } $ext = getExt($_FILES["image"]["name"][$key]); $name = time().$str.$ext; # End new file name if($ext!='.jpg'||$ext!='.gif'){ continue; }else{ move_uploaded_file($tmp_name, "../../images/users/full/$name"); } } } header("Location: /friends/"); exit; ?> Quote Link to comment https://forums.phpfreaks.com/topic/56661-image-upload/ Share on other sites More sharing options...
cooldude832 Posted June 22, 2007 Share Posted June 22, 2007 if you using IE they use the pjpg or pjpeg format try that Quote Link to comment https://forums.phpfreaks.com/topic/56661-image-upload/#findComment-279849 Share on other sites More sharing options...
The Little Guy Posted June 22, 2007 Author Share Posted June 22, 2007 nope, using FF Quote Link to comment https://forums.phpfreaks.com/topic/56661-image-upload/#findComment-279852 Share on other sites More sharing options...
teng84 Posted June 22, 2007 Share Posted June 22, 2007 $tmp_name = $_FILES["image"]["tmp_name"][$key]; check that ???? Astig Quote Link to comment https://forums.phpfreaks.com/topic/56661-image-upload/#findComment-279853 Share on other sites More sharing options...
cooldude832 Posted June 22, 2007 Share Posted June 22, 2007 i'd add it any way because I had a project where i had only .jpg/.gif and the person i was doing it for got frustated with me because it worked in FF not in IE and i didn't know why for a good 2 days Quote Link to comment https://forums.phpfreaks.com/topic/56661-image-upload/#findComment-279855 Share on other sites More sharing options...
The Little Guy Posted June 22, 2007 Author Share Posted June 22, 2007 FF, and IE both return .jpg, or .gif Quote Link to comment https://forums.phpfreaks.com/topic/56661-image-upload/#findComment-279859 Share on other sites More sharing options...
cooldude832 Posted June 22, 2007 Share Posted June 22, 2007 hmm alright hope it doesn't fail i use: <?php if ($HTTP_POST_FILES['imagefile'.$i]['type'] == "image/jpeg" || $HTTP_POST_FILES['imagefile'.$i]['type'] == "image/jpg" || $HTTP_POST_FILES['imagefile'.$i]['type'] == "image/pjpeg" || $HTTP_POST_FILES['imagefile'.$i]['type'] == "image/pjpg") ?> Quote Link to comment https://forums.phpfreaks.com/topic/56661-image-upload/#findComment-279860 Share on other sites More sharing options...
corillo181 Posted June 22, 2007 Share Posted June 22, 2007 works like a charm. instead of looking for a extension type look for the file type. <?php if($filetype = $_FILES['filefield']['type']!='image/pjpeg'){ $save='image/'; $picName=$_FILES['filefield']['name']; $tmpPath=$_FILES['filefield']['tmp_name']; $remove=strstr($picName,'.'); $rand = mt_rand(0, 32); $number = md5($rand . time()).$remove; $result=copy($tmpPath,"$save$number"); } ?> Quote Link to comment https://forums.phpfreaks.com/topic/56661-image-upload/#findComment-279861 Share on other sites More sharing options...
The Little Guy Posted June 22, 2007 Author Share Posted June 22, 2007 I got it! It was an issue with my if statement, it needed to be && and no || Quote Link to comment https://forums.phpfreaks.com/topic/56661-image-upload/#findComment-279863 Share on other sites More sharing options...
cooldude832 Posted June 22, 2007 Share Posted June 22, 2007 ahh I see, yeah I use the image type because then I know its an image,guess it doesn't matter really as we've found out tonight on 10 other questions we've teamed up on Quote Link to comment https://forums.phpfreaks.com/topic/56661-image-upload/#findComment-279866 Share on other sites More sharing options...
corillo181 Posted June 22, 2007 Share Posted June 22, 2007 yeah filytypes really do help a code can be easily trick into reading some thing that has .jpg and then you can add something else .jpg.problemforyou Quote Link to comment https://forums.phpfreaks.com/topic/56661-image-upload/#findComment-279870 Share on other sites More sharing options...
cooldude832 Posted June 22, 2007 Share Posted June 22, 2007 I do a lot of stuff differently, like my random file names/keyphrases are developed off ascii values in the alpha range. Just my style i guess. Works for me so i do it Quote Link to comment https://forums.phpfreaks.com/topic/56661-image-upload/#findComment-279872 Share on other sites More sharing options...
corillo181 Posted June 22, 2007 Share Posted June 22, 2007 i use mt_rand and md5 generate pretty good results for a big website. Quote Link to comment https://forums.phpfreaks.com/topic/56661-image-upload/#findComment-279873 Share on other sites More sharing options...
The Little Guy Posted June 22, 2007 Author Share Posted June 22, 2007 with .jpg.problemforyou my code wont allow it, because it will think the file name is .problemforyou Quote Link to comment https://forums.phpfreaks.com/topic/56661-image-upload/#findComment-279875 Share on other sites More sharing options...
cooldude832 Posted June 22, 2007 Share Posted June 22, 2007 yeah my password recovery: <?php $rnd[0] = chr(rand(48,57)); $rnd[1] = chr(rand(48,57)); $rnd[2] = chr(rand(65,90)); $rnd[3] = chr(rand(65,90)); $rnd[4] = chr(rand(65,90)); $rnd[5] = chr(rand(48,57)); $rnd[6] = chr(rand(48,57)); $newpass = $rnd[0].$rnd[1].$rnd[2].$rnd[3].$rnd[4].$rnd[5].$rnd[6]; $newdbpass = md5($newpass); ?> kinda off topic but whatever Quote Link to comment https://forums.phpfreaks.com/topic/56661-image-upload/#findComment-279877 Share on other sites More sharing options...
corillo181 Posted June 22, 2007 Share Posted June 22, 2007 thats a long way to go for something that can be done with mt_rand to create a random set of num ad md5 has more probability Quote Link to comment https://forums.phpfreaks.com/topic/56661-image-upload/#findComment-279886 Share on other sites More sharing options...
cooldude832 Posted June 22, 2007 Share Posted June 22, 2007 yeah well i was looking for an alphanumerical solution for a greater number of permutations. 37p6 is about 2.5 billion 9p10 is about 3.5 billion, but it odds of repeated characters is much greater I rather have alphanumerical than that extra billion permutations Quote Link to comment https://forums.phpfreaks.com/topic/56661-image-upload/#findComment-279891 Share on other sites More sharing options...
corillo181 Posted June 22, 2007 Share Posted June 22, 2007 i guess you got that one. Quote Link to comment https://forums.phpfreaks.com/topic/56661-image-upload/#findComment-279897 Share on other sites More sharing options...
cooldude832 Posted June 22, 2007 Share Posted June 22, 2007 also if i move to 37p7 i'm in the 15 billion range Quote Link to comment https://forums.phpfreaks.com/topic/56661-image-upload/#findComment-279900 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.