473,803 Members | 2,279 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

PHP + Upload + picture script

I was wondering if anyone does any uploading picture scripts or how to
do it where i could upload a picture and use php to change the picture
size to what i want it to be. Anyone know where i could learn how to do
this or have any script examples? i would really appreciate it alot.

thanks for you time

jason

Oct 30 '06 #1
5 1890
For the uploading part, here's some basic code:
<?php
if(@$_POST['MAX_FILE_SIZE']){ // If it is actually uploading
something...
$uploadfile = $uploaddir . basename($_FILE S['userfile']['name']);
//SET YOUR OWN UPLOAD DIR (absolute)
if (move_uploaded_ file($_FILES['userfile']['tmp_name'], $uploadfile)){
echo "File was successfully uploaded!\n You can access the file at:
http://".ROOT_DOMAIN.$ uploaddir.basen ame($_FILES['userfile']['name'])."\n";
} else {
echo "Error! File was not uploaded!\n";
};
};
?>
<form action="<?php echo $_SERVER['PHP_SELF']; ?>?admin=<?php echo
ADMIN_PAGE; ?>" method="POST" enctype="multip art/form-data">
<input type="hidden" name="MAX_FILE_ SIZE" value="300000" />
<input type="file" name="userfile" /><br />
<input type="submit" value="Upload" />
</form>

You can find a basic image resizing script @ php.net under GD2
functions -

<?php
function CreateThumb($fi le,$maxwdt,$max hgt, $dest) {
list($owdt,$ohg t,$otype)=@geti magesize($file) ;

switch($otype) {
case 1: $newimg=imagecr eatefromgif($fi le); break;
case 2: $newimg=imagecr eatefromjpeg($f ile); break;
case 3: $newimg=imagecr eatefrompng($fi le); break;
default: echo "Unkown filetype (file $file, typ $otype)"; return;
}

if($newimg) {
if($owdt>1500 || $ohgt>1200)
list($owdt, $ohgt) = Resample($newim g, $owdt, $ohgt,
1024,768,0);

Resample($newim g, $owdt, $ohgt, $maxwdt, $maxhgt);

if(!$dest) return $newimg;

if(!is_dir(dirn ame($dest)))
mkdir(dirname($ dest));

switch($otype) {
case 1: imagegif($newim g,dest); break;
case 2: imagejpeg($newi mg,$dest,90); break;
case 3: imagepng($newim g,$dest); break;
}

imagedestroy($n ewimg);

chmod($dest,064 4);
}
}

function Resample(&$img, $owdt, $ohgt, $maxwdt, $maxhgt, $quality=1) {
if(!$maxwdt) $divwdt=0;
else $divwdt=Max(1,$ owdt/$maxwdt);

if(!$maxhgt) $divhgt=0;
else $divhgt=Max(1,$ ohgt/$maxhgt);

if($divwdt>=$di vhgt) {
$newwdt=$maxwdt ;
$newhgt=round($ ohgt/$divwdt);
} else {
$newhgt=$maxhgt ;
$newwdt=round($ owdt/$divhgt);
}

$tn=imagecreate truecolor($neww dt,$newhgt);
if($quality)

imagecopyresamp led($tn,$img,0, 0,0,0,$newwdt,$ newhgt,$owdt,$o hgt);

else
imagecopyresize d($tn,$img,0,0, 0,0,$newwdt,$ne whgt,$owdt,$ohg t);

imagedestroy($i mg);

$img = $tn;

return array($newwdt, $newhgt);
}
?>

just use the function create thumb to set the dimensions and the
destination file

*There is a script that will work out the % size for you on php.net, if
you need %s*

On Oct 30, 5:19 pm, "jason.ta...@gm ail.com" <jason.ta...@gm ail.com>
wrote:
I was wondering if anyone does any uploading picture scripts or how to
do it where i could upload a picture and use php to change the picture
size to what i want it to be. Anyone know where i could learn how to do
this or have any script examples? i would really appreciate it alot.

thanks for you time

jason
Oct 30 '06 #2
<ja*********@gm ail.comwrote in message
news:11******** **************@ m7g2000cwm.goog legroups.com...
>I was wondering if anyone does any uploading picture scripts or how to
do it where i could upload a picture and use php to change the picture
size to what i want it to be. Anyone know where i could learn how to do
this or have any script examples? i would really appreciate it alot.

thanks for you time

jason
I developed a little script that I used only for jpegs so far. I haven't
tested it with other image types. Here it is:

function thumbnail($img, $w_d, $h_d) {
// $img is the image
// $w_d is the desired width in pixels
// $h_d is the desired height in pixels
//
// function to get the width and height to display q thumbnail
// Pass in the image location, the deisred width and the desired height
// Ouput is an array of height and width to display that can be
// exploded with the list commant
list($w, $h, $type, $attr) = getimagesize($i mg);
$calc_width = $h_d * $w / $h;
$calc_height = $w_d * $h / $w;
if ($calc_width <= $w_d) {
$disp_width = $calc_width;
$disp_height = $h_d;
} else {
$disp_width = $w_d;
$disp_height = $calc_height;
}
return array($disp_wid th, $disp_height);
}
I call it with:

list($disp_widt h, $disp_height) = thumbnail($the_ picture_locatio n, 500,
500);

and in the html area I have:

<img src="the-picture-location" width="<?php echo $disp_height;?> "
height="<?php echo $disp_height;?> "
border="0" alt="something here" align="bottom" />

Hope that helps.

Shelly


Oct 30 '06 #3
>
On Oct 30, 5:19 pm, "jason.ta...@gm ail.com" <jason.ta...@gm ail.com>
wrote:
I was wondering if anyone does any uploading picture scripts or how to
do it where i could upload a picture and use php to change the picture
size to what i want it to be. Anyone know where i could learn how to do
this or have any script examples? i would really appreciate it alot.

thanks for you time

jason

Take a look on the phpclasses.org site. You will need to register but
I've never had a problem from there.
There are some excellent and well documented class files that can be
used to handle image resize (amongst other things) and by reading over
the code you can learn how they work while solving a problem straight
away.
Hope that helps
b

Oct 31 '06 #4
ja*********@gma il.com wrote:
I was wondering if anyone does any uploading picture scripts or how to
do it where i could upload a picture and use php to change the picture
size to what i want it to be. Anyone know where i could learn how to
do this or have any script examples? i would really appreciate it
alot.
Actually, I developed just that type of function for a member system
where members would be able to upload a photo of themselves.

Here's the code snippet along with usage:
http://dev.bd0.net/test/image_upload_convert.phps

The function will accept JPEG, GIF and PNG files as input and by
default output a JPEG file.

--
Kim André Akerĝ
- ki******@NOSPAM betadome.com
(remove NOSPAM to contact me directly)
Oct 31 '06 #5
aussiebob schreef:
>On Oct 30, 5:19 pm, "jason.ta...@gm ail.com" <jason.ta...@gm ail.com>
wrote:
>>I was wondering if anyone does any uploading picture scripts or how to
do it where i could upload a picture and use php to change the picture
size to what i want it to be. Anyone know where i could learn how to do
this or have any script examples? i would really appreciate it alot.

thanks for you time

jason


Take a look on the phpclasses.org site. You will need to register but
I've never had a problem from there.
There are some excellent and well documented class files that can be
used to handle image resize (amongst other things) and by reading over
the code you can learn how they work while solving a problem straight
away.
Hope that helps
b

I agree ... I just posted a modified script in alt.php that I downloaded
from phpclasses that exactly fits your needs
Oct 31 '06 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
711
by: Phillip Parr | last post by:
I'm trying to get a file upload to work and it's not happening. Here's my form code... echo '<form enctype="multipart/form-data" action="catalogue.php" method="post"> <input type="hidden" name="MAX_FILE_SIZE" value="204800"> <table border="0" width="100%"> <tr> <td width=100%> <center>
2
1905
by: Ken | last post by:
I am trying to upload a file to an Apache2 server on Windows 2000 Pro. The temp file name is being added to the database. Everything seems to work except the file is not actually transferred to the directory. I have searched the entire hard drive for the temp file name but it is not saved. I have tried both defining and not defining upload_tmp_dir in PHP.ini Both directories have had share activated.
2
2660
by: NotGiven | last post by:
Please help me understand the big picture of allowing users to upload pictures and keep them separate and tied to their record in the database. I want the whole thing automated and I'm just trying to get my arms around what all is entailed. Each user will upload about 20 - 100 pictures and each will be related to a different database record. I see the process in general as this:
9
3847
by: Wayne Smith | last post by:
I've come up against a major headache that I can't seem to find a solution for but I'm sure there must be a workaround and I would really be grateful of any help. I'm currently building a web site for a small club I belong to and one of the features I would like to include is the ability to allow users to upload image files. unfortunately the servers web root www folder only allows READ and EXECUTE permissions, which makes it...
7
2559
tolkienarda
by: tolkienarda | last post by:
hi all I am using a php script to try to upload images to my database. i know i am connecting to my database because the image title is being wirtten to the database. but the image isn't example: if i upload the coke emblem from my desktop and type in 'coke'; when i look into the phpmyadmin i see that the text coke was written to the database but in the pix field it said below is the code if anyone has insight i would be grateful this...
21
34446
KevinADC
by: KevinADC | last post by:
Note: You may skip to the end of the article if all you want is the perl code. Introduction Uploading files from a local computer to a remote web server has many useful purposes, the most obvious of which is the sharing of files. For example, you upload images to a server to share them with other people over the Internet. Perl comes ready equipped for uploading files via the CGI.pm module, which has long been a core module and allows users...
6
2106
by: aanund | last post by:
I don't know if I'm in the right place, or doing this properly, but I hope someone sees it anyway. I am a rookin i PHP, yet I have found this to be an efficient and useful scripting language for many tasks. What I know would like to enquire about is this: I have got hold of a php-script that helps me upload files to a certain folder on my server. Originally this was meant to be used for picture upload. The uploading works fine, but what I...
3
1485
by: thesti | last post by:
hi, i dunno why, but i have tested my upload script with IE 6. but the file wasn't uploaded. it works fine with Opera and FF. i use php 5.1.2 here is my upload script //get the picture file //validation on type and size $fileName = '';
24
7735
by: owz2008 | last post by:
This has probably been covered before but could not find a similar thread. Basically I have created a form which can be viewed at www.icomworks.co.uk/canvaspayform.html I want to submit the form along with the file so that they are both placed on my server... I have created a folder on my server in my public_html called myscripts and have saved my upload.cgi script into that folder. my form points to that script but when I fill in the...
0
10542
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10309
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10289
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10068
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
6840
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5496
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5625
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3795
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2968
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.