Jump to content

Explode?


Wolphie

Recommended Posts

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.

Link to comment
Share on other sites

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.

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.