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?

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

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.