Wolphie Posted November 13, 2007 Share Posted November 13, 2007 I'm pretty baffled at this. I'm not entirely sure why this isn't working: $filetype = $_POST['file']['type']; // getting the file type $file = explode('.', $filetype); // exploding the string to return just the file type $filename = rand() . '.' . $file[1]; // renaming it and then adding the file type back to save the file I'm trying to retrieve the file type seperately and then rename it. Quote Link to comment Share on other sites More sharing options...
kenrbnsn Posted November 13, 2007 Share Posted November 13, 2007 What is your question? What are you trying to do? Ken Quote Link to comment Share on other sites More sharing options...
Wolphie Posted November 13, 2007 Author Share Posted November 13, 2007 *edited* Quote Link to comment Share on other sites More sharing options...
revraz Posted November 13, 2007 Share Posted November 13, 2007 What is in this array? $_POST['file']['type'] Why not just pull the last three characters of the string? Quote Link to comment Share on other sites More sharing options...
Wolphie Posted November 13, 2007 Author Share Posted November 13, 2007 That's what i'm trying to do Quote Link to comment Share on other sites More sharing options...
Wolphie Posted November 13, 2007 Author Share Posted November 13, 2007 Sorry, i just got extremely confused and made a typo. It's meant to be $_FILES['file']['name']; I'm just tired, and been coding all day. Getting too much. -.- Quote Link to comment Share on other sites More sharing options...
gin Posted November 14, 2007 Share Posted November 14, 2007 What's the error? I can't see anything wrong with that piece of code. Quote Link to comment Share on other sites More sharing options...
pocobueno1388 Posted November 14, 2007 Share Posted November 14, 2007 Take this for example <?php if (isset($_POST['upload'])){ $name = $_FILES['uploadedfile']['name']; //The name of the file, EX - name.jpg $name = explode('.', $name); $ext = $name[1]; //The type of file/extension, EX - .jpg echo $ext; } ?> <form enctype="multipart/form-data" action="z.php" method="POST"> <input type="hidden" name="MAX_FILE_SIZE" value="100000" /> Choose a file to upload: <input name="uploadedfile" type="file" /><br /> <input type="submit" value="Upload File" /> </form> You need to use the $_FILES variable to retrieve information about the file. First take a look at this line $name = $_FILES['uploadedfile']['name']; Where it says "uploadedfile", that is where you need to put the name of the input, which in the example, comes from this line Choose a file to upload: <input name="uploadedfile" type="file" /><br /> See if you can work out your problem by looking at that, if not just let us know. 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.