Jump to content

Getting file extension on upload


davelearning

Recommended Posts

Hi Guys,

 

I am having some issues in trying to return a file extension in a php upload script, here is what I am trying to do, no extension is added when a file is uploaded.

 


$p_id = $row['p_id'];

		$tempFile = $_FILES['Filedata']['tmp_name'];
		$targetPath = $_SERVER['DOCUMENT_ROOT'] . $_REQUEST['folder'] . '/';
		$filename = $HTTP_POST_FILES['Filedata']['name'];
		$ext = end(explode('.', $filename));
		$nfilename = $p_id . $ext;


		$targetFile =  str_replace('//','/',$targetPath) . $nfilename;

Link to comment
Share on other sites

Thanks for your reply, however

 

$p_id = $row['p_id'];

		$tempFile = $_FILES['Filedata']['tmp_name'];
		$targetPath = $_SERVER['DOCUMENT_ROOT'] . $_REQUEST['folder'] . '/';
		$filename = $HTTP_POST_FILES['Filedata']['name'];
		$ext = pathinfo($filename, PATHINFO_EXTENSION);
		$nfilename = $p_id . $ext;


		$targetFile =  str_replace('//','/',$targetPath) . $nfilename;

 

Gives the same result as before

Link to comment
Share on other sites

Thanks to everyone! Got it!

 

$aquery = mysql_query("SELECT p_id FROM images WHERE p_id = '$l_id'");
while($row = mysql_fetch_assoc($aquery))
  	{
		$p_id = $row['p_id'];

		$tempFile = $_FILES['Filedata']['tmp_name'];
		$targetPath = $_SERVER['DOCUMENT_ROOT'] . $_REQUEST['folder'] . '/';
		$filename = $_FILES['Filedata']['name'];
		$ext = pathinfo($filename, PATHINFO_EXTENSION);
		$nfilename =  '' . $p_id . '.' . $ext .'';


		$targetFile =  str_replace('//','/',$targetPath) . $nfilename;



	}

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.