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
https://forums.phpfreaks.com/topic/77212-explode/
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
https://forums.phpfreaks.com/topic/77212-explode/#findComment-391138
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.