Jump to content

[SOLVED] Need Help! Upload jpg images.


cyrixware

Recommended Posts

Hi, is ther any idea how to upload jpg images. Let say for exmple, I have a text box and browse button.After  i click the button that says upload the image will upload. Then when i click the button view the images will view. How can i do that? I need your help... pls send me a codes for that...

 

And also i have a question uhmm... where is that images save? is ther a folder that all images will save or the images will save on the dbase?

 

Regards,

 

- Cyrixware ;)

Link to comment
https://forums.phpfreaks.com/topic/46957-solved-need-help-upload-jpg-images/
Share on other sites

html form:

 

<form method="POST" enctype="multipart/form-data" action="playwith.php">
<p>
<input type="file" name="userfile" size="20">
<input type="submit" value="Submit" name="B1"><input type="reset" value="Reset" name="B2">
</p>
</form>

 

PHP handler

 

<?php
$filesize = $_FILES['userfile']['size']; 
$filetype = $_FILES['userfile']['type']; 
$nameuse = filename;
IF (($filesize <= 102000) AND ($filetype == 'image/pjpeg') OR ($filetype == 'image/jpeg'))
{

$nameuse = "$nameuse.jpg";
// In PHP versions earlier than 4.1.0, $HTTP_POST_FILES should be used instead
// of $_FILES.
$uploaddir = '/home/yoursection/public_html/uploads/';
$uploadfile = $uploaddir . $nameuse;
echo '<pre>';
if (move_uploaded_file($_FILES['userfile']['tmp_name'], $uploadfile)) 
	{

   		echo "File is valid, and was successfully uploaded.\n";
	} 
else 
	{
   		echo "Possible file upload attack!";
	}
}
IF (($filetype != 'image/pjpeg') AND ($filetype != 'image/jpeg'))
	{
   		echo "Your Image is the wrong file type, it must be a jpg image<BR>your image is $filetype";
	}
IF ($filesize > 102000)
{
echo "Your Image is to large to upload";
}
?> 

thanks for the reply... should i create a single image folder directory  for the locations of the images uploaded?

 

or should i creat this directory?

 

$uploaddir = '/home/yoursection/public_html/uploads/';

 

:)

 

i use localhost in my pc...

 

ex:

 

http://localhost/uploads/playwith.php

 

then uploads folder :

 

http://localhost/uploads/uploads

 

 

 

ok i get it now.. the problem is that when i try to upload another image again the previous image deleted itself automatically... meaning in a sigle folder only 1 image can be stored.. how can i store more than a single image? thanks again

 

Regards,

Cyrix

 

html form:

 

<form method="POST" enctype="multipart/form-data" action="playwith.php">
<p>
<input type="file" name="userfile" size="20">
<input type="submit" value="Submit" name="B1"><input type="reset" value="Reset" name="B2">
</p>
</form>

 

PHP handler

 

<?php
$filesize = $_FILES['userfile']['size']; 
$filetype = $_FILES['userfile']['type']; 
$nameuse = filename;
IF (($filesize <= 102000) AND ($filetype == 'image/pjpeg') OR ($filetype == 'image/jpeg'))
{

$nameuse = "$nameuse.jpg";
// In PHP versions earlier than 4.1.0, $HTTP_POST_FILES should be used instead
// of $_FILES.
$uploaddir = '/home/yoursection/public_html/uploads/';
$uploadfile = $uploaddir . $nameuse;
echo '<pre>';
if (move_uploaded_file($_FILES['userfile']['tmp_name'], $uploadfile)) 
	{

   		echo "File is valid, and was successfully uploaded.\n";
	} 
else 
	{
   		echo "Possible file upload attack!";
	}
}
IF (($filetype != 'image/pjpeg') AND ($filetype != 'image/jpeg'))
	{
   		echo "Your Image is the wrong file type, it must be a jpg image<BR>your image is $filetype";
	}
IF ($filesize > 102000)
{
echo "Your Image is to large to upload";
}
?> 

as Heyray said, you want to change that line, but, if you have random people uploading its possible for them to overwrite each others files when they upload... the way I have it on my actual page is I use a timestamp basically for the file name, looks like this

 

$nameuse  = gmdate("YmdHis");

 

This way, the only way you get two with the same name is if they are posted at the exact same second

gotcha! :)

 

 

I have a problem about deleting images. I created 2 folders, 1st the folder IMAGES wherein the actual size of the images uploaded stored here. The other folder named THUMB stored the images i set the size use for my thumbnails in picture gallery. The problem is that, i dont know how to delete the images both folders. Let say for example, im going to browse the image then when i click delete the image deleted automatically in both folders. (Both folders is the same filename of the images inside)

 

thanks

i dont know how to delete the images in both folders at the same time.. pls help em.. thanks

 

Folders:

 

1. IMAGES: pic.jpg

2. THUMB : pic.jpg

 

Im going to browse the image after that if im going to click delete the images pic.jpg in folder IMAGES and THUMBS deleted automatically. How can i do that? :)

 

 

 

 

 

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.