php upload image...

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
Alidad
Forum Commoner
Posts: 29
Joined: Thu Mar 29, 2007 12:42 pm

php upload image...

Post by Alidad »

Hi, I need help with php, I’m still rookie with php, I bought the component relate to image editor where allow me to change it such as crop, resize etc on the image.. but One of the line where it said

<img src="image.jpg" class="kroppr" />

That line is for showing image, and if I want to change image, I really hate to change image by type image name, what I like to use upload features, my question is that how can I write that code using upload features to upload image on the image editor.
<html>
<body>
<form action="" method="post"
enctype="multipart/form-data">
<label for="file">Filename:</label>
<input type="file" name="file" id="file" />
<br />
<input type="submit" name="submit" value="Submit" />

<img src="image.jpg" class="kroppr" />

</form>
</body>
</html>
Randwulf
Forum Commoner
Posts: 63
Joined: Wed Jan 07, 2009 7:07 am

Re: php upload image...

Post by Randwulf »

I'm not 100% sure that I know what it is you're trying to do. You want to be able to upload an image and then change the <img src="image.jpg" class="kroppr" /> line to something that will show the uploaded image?

If that's the case, and assuming that a function to save the file to the same folder on the server is already in place (if its not, let me know and I can help with that too) then you could do this:

Code: Select all

 
if (isset($_FILES['file']['fileitemname']['name']))
{
$str = file_get_contents("phpfilenamehere.php");
$str = str_replace("image.jpg",$_FILES['file']['fileitemname']['name'],$str);
$handle = fopen("phpfilenamehere.php",'w');
fwrite($handle,$str);
fclose($handle);
}
 
And that would change <img src="image.jpg" class="kroppr" /> on that page to <img src="whatever.jpg" class="kroppr" />

If you do need a function to upload the picture, check this out: http://www.tizag.com/phpT/fileupload.php
Post Reply