Ask a Question related to PHP Development, Design and Development.
-
Vertex #1
A couple GD image questions
I have been working on the below snippet of code I found some place
and have a couple questions on it since I am not real femiliar with
the GD image commands.
1. How would I define a custom path to save the pictures in instead of
just putting the finished pictures in the same directory as the php
file.
2. How could I use the original file name of the picture and store
that in the database rather than renaming the file.
This is what I am working with
--------
<?php include 'db_connect.php'; ?>
<html>
<head>
<title>Upload a picture to your article</title>
<meta http-equiv="Content-Type" content="text/html;
charset=iso-8859-1">
</head>
<body>
<?php
articleid = artid;
//begin photo upload code
if (isset(_POST['photosubmit']))
{
// Filename to store image as (no extention)
FILENAME= rand(0,999999999);
// Width to reszie image to (in pixels)
RESIZEWIDTH=300;
// Width to reszie image to (in pixels)
RESIZEHEIGHT=400;
//start image function
function
ResizeImage(im,maxwidth,maxheight,name){
width = imagesx(im);
height = imagesy(im);
if((maxwidth && width >
maxwidth) || (maxheight && heightif(maxwidth && width >> maxheight)){
maxwidth){
widthratio = maxwidth/width;
RESIZEWIDTH=true;
}
if(maxheight && height >
maxheight){
heightratio = maxheight/height;
RESIZEHEIGHT=true;
}
if(RESIZEWIDTH && RESIZEHEIGHT){
if(widthratio < heightratio){
ratio = widthratio;
}else{
ratio = heightratio;
}
}elseif(RESIZEWIDTH){
ratio = widthratio;
}elseif(RESIZEHEIGHT){
ratio = heightratio;
}
newwidth = width * ratio;
newheight = height *
ratio;
if(function_exists("imagecopyresampled")){
newim =
imagecreatetruecolor(newwidth, newheight);
imagecopyresampled(newim,
im, 0, 0, 0, 0, newwidth, newheight, width,
height);
}else{
newim = imagecreate(newwidth,
newheight);
imagecopyresized(newim,
im, 0, 0, 0, 0, newwidth, newheight, width,
height);
}
ImageJpeg (newim,name .
".jpg");
ImageDestroy (newim);
} else {
ImageJpeg (im,name . ".jpg");
}
}
//end image function
if(_FILES['image']['size']){
if(_FILES['image']['type']
== "image/pjpeg" ||
_FILES['image']['type'] ==
"image/jpeg"){
im =
imagecreatefromjpeg(_FILES['image']['tmp_name']);
}elseif(_FILES['image']['type']
== "image/x-png" ||
_FILES['image']['type'] ==
"image/png"){
im =
imagecreatefrompng(_FILES['image']['tmp_name']);
}elseif(_FILES['image']['type']
== "image/gif"){
im =
imagecreatefromgif(_FILES['image']['tmp_name']);
}
if(im){
if(file_exists("FILENAME.jpg")){
unlink("FILENAME.jpg");
}
ResizeImage(im,RESIZEWIDTH,RESIZEHEIGHT,FILENA ME);
ImageDestroy (im);
}
//Submit picture
insert = "INSERT INTO pictures (
article_ref,
pic_name)
VALUES (
'articleid',
'".FILENAME.".jpg')";
article_pic = db_object->query(insert);
if (DB::isError(article_pic)) {
die(article_pic->getMessage());
}
db_object->disconnect();
?>
<B>Picture added successfully!</B> You can either
close this window or upload more pictures.
<?php
}
}
//end upload photo
?>
<form enctype="multipart/form-data"
method="post">
<b>Upload Image</b><br>
<input type="file" name="image"
size="50"><br>
<input type="submit" name="photosubmit"
value="Upload Photo"
onclick='refreshIframe()'>
</form>
</body>
</html>
--------
Thanks a million for any help on this problem!!! :D
----------------------------------------
The post originated from PHP Freaks:
----------------------------------------
[url]http://www.phpfreaks.com[/url]
[url]http://www.phpfreaks.com/forums[/url]
Vertex Guest
-
A couple of questions
I have a Canon A60 and .... 1) I really need to pick up some rechargable AA NiMH batteries. I see packages like this... -
Flash and .NET...a couple questions
I was thinking about creating an app using flash and .net but had a few questions on the best way to go about doing things. Is it best practise to... -
A couple of questions before I buy....
Hi, I have been playing with a 30 day trial version of Contribute 3 and have a couple of questions before I buy. 1. My page uses CSS buttons,... -
Please help with a couple questions!!!
I just bought adobe 6.0 standard and my system is win. xp I wrote my book in ms word and then hit the adobe convert button and when it converted... -
I have a couple of questions.
First, I would like to know if there is anyway to add a watermark to pictures, that will only show up only when the photo is printed. My husband... -
parksmike #2
Re: A couple GD image questions
Try using this:
move_uploaded_file ( string filename, string destination)
----------------------------------------
The post originated from PHP Freaks:
----------------------------------------
[url]http://www.phpfreaks.com[/url]
[url]http://www.phpfreaks.com/forums[/url]
parksmike Guest



Reply With Quote

