Jump to content

[SOLVED] path from input type file tag (ie vs firefox)


bigtimslim

Recommended Posts

I have a php script that takes an image and edits it. I want the user to be able to select an image from his local machine. I thought to do this I would use input type file to get the path from the nice browse for file dialog. 

 

This works fine in IE, but with firefox i get errors. I printed the path to see what was going on and saw that all I was getting with firefox was the filename and extension.. without the full path.

 

I need the full path, can anyone help?

Link to comment
Share on other sites

ok, code it is:

 

<?php

// Check if the form has been submitted:
if (isset($_POST['submitted'])) {

$errors = array(); 

// Check for file:
if (empty($_POST['file'])) {
	$errors[] = 'You forgot to specify a file.';
} else {
	$f = $_POST['file'];
}

// Check for text:
if (empty($_POST['text'])) {
	$errors[] = 'You forgot to enter text.';
} else {
	$t = $_POST['text'];
}

if (empty($errors)) { 	
	echo $f;
	exit();
} else { 
	echo '<h1>Error!</h1>
	<p class="error">The following error(s) occurred:<br />';
	foreach ($errors as $msg) { // Print each error.
		echo " - $msg<br />\n";
	}
	echo '</p><p>Please try again.</p><p><br /></p>';	
} 
} 
?>

<form action="bleh.php" method="post">
<p>Image File: <input type="file" name="file" id="file" value="<?php if (isset($_POST['file'])) echo $_POST['file']; ?>"  /></p>
<p>Image Text: <input type="text" name="text" size="15" maxlength="15" value="<?php if (isset($_POST['text'])) echo $_POST['text']; ?>" /></p>
<p><input type="submit" name="submit" value="submit" /></p>
<input type="hidden" name="submitted" value="TRUE" />
</form>

 

When I run this in firerfox, I get: filename.jpg

In IE if get: C:\\Users\\Tim\\Desktop\\filename.jpg

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.