FairyBusiness
asked on
How to parse an image file in php?
Hello,
I am trying to get only the image name of an uploaded file. I thought this would work:
$image = mysql_clean_strings($_POST ['image']) ;
$image = basename($_FILES[$image][' name']);
but its not. Any ideas?
I am trying to get only the image name of an uploaded file. I thought this would work:
$image = mysql_clean_strings($_POST
$image = basename($_FILES[$image]['
but its not. Any ideas?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
What is your image field name called?
ASKER
<input id="image" type="file" name="image" value="" />
That is basically saying that the image field is not between the form tags
ASKER
<form method="post" action="edit_product.php?edit=<?php echo $table ?>&item=<?php echo ($_GET['item']); ?>">
<input type="text" name="name" value="<?php echo strip_tags(headers()); ?>" class="textLg" />
<br style="clear: both;" />
<iframe id="preview" src="<?php echo display();?>"></iframe>
<div id="info">
<textarea name="content">
<?php echo get_data($field='content', $table);?>
</textarea>
<h4>Materials</h4>
<div id="materials">
<?php
get_table_material();
echo materials();
?>
</div><!-- end #materials -->
</div><!-- end #info -->
<div id="options">
<input type="text" name="price" value="$<?php echo get_data($field='price', $table); ?>" /><p>
Color: <br />
<input type="text" name="color" value="<?php echo color(); ?>" />
<?php
echo qty();
$item = get_item();
?>
</div><!-- end #options -->
<br style="clear: left;" />
<label>Image: <input id="image" type="file" name="image" value="" /></label>
<p>
<label>Metal Id: <input type="text" name="metal_id" value="<?php echo get_data($field='metal_id', $table);?>" class="textSm" /></label>
<label>Featured: Yes <input type="checkbox" name="featured" value="1" />No <input type="checkbox" name="featured" value="0" checked /></label>
<label>In Stock: Yes <input type="checkbox" name="stock" value="1" checked />No <input type="checkbox" name="stock" value="0" /></label>
</p>
<input type="submit" name="submit" value="Update" /></a>
</form>
ASKER
Ok, I used a var_dump on my $image and I got this back
string(7) "n16.png"
By basename I wanted it without the image type. .. I do I remove the file type .png (short of removing the characters of the string)
string(7) "n16.png"
By basename I wanted it without the image type. .. I do I remove the file type .png (short of removing the characters of the string)
Are you wanting to make it a png?
I mean a jpg?
ASKER
No, I want it to be a png. But I use the file name n17 or whatever as the item name throughout my website so when I retrieve the file name I don't want the .png with it
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
but will that just return the first character? or everything before the period?
Everything before the period
ASKER
Thanks again :)
ASKER
Notice: Undefined index: image in /hermes/web09c/b2950/moo.a
When I did only this:
$image = basename($_FILES['image'][
This is the whole function:
Open in new window