CrazeD Posted June 21, 2007 Share Posted June 21, 2007 I'm working on an image gallery. I've never done this sort of thing before with uploads and whatnot, so I'm working the bugs out of my upload script. I can't seem to make it upload a .jpeg extension. What gives? <?php if (isset ($_POST['submit'])) { if ($_FILES['file']['type'] == "image/gif") { $type = ".gif"; } elseif ($_FILES['file']['type'] == "image/jpeg") { $type = ".jpg"; } $rand = rand(1,10000000); if (($_FILES["file"]["type"] == "image/gif") || ($_FILES["file"]["type"] == "image/djpeg") && ($_FILES["file"]["size"] < 2000000)) { if ($_FILES["file"]["error"] > 0) { echo "Return Code: " . $_FILES["file"]["error"] . "<br />"; } else { echo "Upload: " . $_FILES["file"]["name"] . "<br />"; echo "Type: " . $_FILES["file"]["type"] . "<br />"; echo "Size: " . ($_FILES["file"]["size"] / 1024) . " Kb<br />"; echo "Temp file: " . $_FILES["file"]["tmp_name"] . "<br />"; if (file_exists("uploads/".$rand."" . $_FILES["name"])) { echo $_FILES['file']["name"] . " already exists. "; } else { move_uploaded_file($_FILES["file"]["tmp_name"], 'uploads/'.$rand.''.$type.''); echo "Stored in: " . "upload/" . $_FILES["file"]["name"]; print '<p>'.$type.'</p>'; } } } else { echo "Invalid file"; } } else { ?> <form action="gallery.php" enctype="multipart/form-data" method="post"> <input type="hidden" name="MAX_FILE_SIZE" value="30000" /> <input type="file" name="file" /><br /> <input type="submit" name="submit" value="Upload" /> </form> <?php } ?> Quote Link to comment https://forums.phpfreaks.com/topic/56617-solved-help-with-upload-script/ Share on other sites More sharing options...
CrazeD Posted June 22, 2007 Author Share Posted June 22, 2007 Anyone? I'd like to get rollin with this. Quote Link to comment https://forums.phpfreaks.com/topic/56617-solved-help-with-upload-script/#findComment-279923 Share on other sites More sharing options...
corillo181 Posted June 22, 2007 Share Posted June 22, 2007 error on your image/dpjpeg needs to be image/pjpeg Quote Link to comment https://forums.phpfreaks.com/topic/56617-solved-help-with-upload-script/#findComment-279928 Share on other sites More sharing options...
CrazeD Posted June 22, 2007 Author Share Posted June 22, 2007 Okay I tried that and that didn't work either. Just says invalid file. I had it as image/jpeg at first, according to this it should work: http://www.phpfreaks.com/mimetypes.php Quote Link to comment https://forums.phpfreaks.com/topic/56617-solved-help-with-upload-script/#findComment-279933 Share on other sites More sharing options...
CrazeD Posted June 22, 2007 Author Share Posted June 22, 2007 I had copied this script off a tutorial because I was too lazy to write my own. I ended up writing my own anyway and that fixed my problem. Thanks anyways guys. Quote Link to comment https://forums.phpfreaks.com/topic/56617-solved-help-with-upload-script/#findComment-279966 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.