Page 1 of 1
Image upload with Flash, resize with PHP
Posted: Thu Apr 24, 2008 3:46 am
by bebensiganteng
Everah | Please use descriptive titles when posting in the forums. I have edited your post title to show it like we would like to see it.
Hi Guys,
I'm trying to make an image upload through flash, and resize it in the php, but for some reason the file doesnt get copied within the server, see the code below
Code: Select all
$imageDirectory = "Common/Media/Images";
// EXECUTING
//-------------------------------------------------------------------------
if(!is_dir($imageDirectory)) mkdir($imageDirectory, 0755);
$fileNames = $_FILES['Filedata']['name'];
$uniqueId = "Common/Media/Images/".$_GET['fileId'].".jpg";
$imageFile = $uniqueId;
// Get new sizes
list($width, $height) = getimagesize($_FILES['Filedata']['tmp_name']);
$newwidth = 640;
$newheight = 480;
// Load
$new = imagecreatetruecolor($newwidth, $newheight);
$source = imagecreatefromjpeg($_FILES['Filedata']['tmp_name']);
// Resize
imagecopyresized($new, $source, 0, 0, 0, 0, $newwidth, $newheight, $width, $height);
// Output
imagejpeg($new, $imageFile);
but when i use
Code: Select all
move_uploaded_file($source, $imageFile);
the file get copied, any reason why?
Thanks
Re: Newbie question
Posted: Thu Apr 24, 2008 4:42 am
by aceconcepts
When you initially "upload" a file it is stored in a temporary directory "tmp/..." something like that. You need to tell the server where you want to move to using move_uploaded_file().
Re: Newbie question
Posted: Mon Apr 28, 2008 8:26 am
by bebensiganteng
Hi Thanks for the reply,
Well the move_uploaded_file() works when I used it, but the image doesnt get resized
What i want is for the image to get resized first then stored in the server
The weird thing is on my previous code (please see my first post) worked fine when I tried it on my local, the image gets resized and stored perfectly
But when I upload the php to the actual server.. it fails
and i also tried to mix 2 method together (which i dont think is right), and still it fails
below is my code with 2 method to gether:
Code: Select all
$imageDirectory = "Common/Media/Images";
// EXECUTING
//-------------------------------------------------------------------------
if(!is_dir($imageDirectory)) mkdir($imageDirectory, 0755);
$fileNames = $_FILES['Filedata']['name'];
$uniqueId = "Common/Media/Images/".$_GET['fileId'].".jpg";
$imageFile = $uniqueId;
// Get new sizes
list($width, $height) = getimagesize($_FILES['Filedata']['tmp_name']);
$newwidth = 640;
$newheight = 480;
// Load
$new = imagecreatetruecolor($newwidth, $newheight);
$source = imagecreatefromjpeg($_FILES['Filedata']['tmp_name']);
// Resize
imagecopyresized($new, $source, 0, 0, 0, 0, $newwidth, $newheight, $width, $height);
// Output
imagejpeg($new, $imageFile);
move_uploaded_file($new, $imageFile);
chmod($imageFile, 0777);
if you guys have any experience with this, please please advice...
Thanks in advance
Re: Newbie question
Posted: Mon Apr 28, 2008 8:43 am
by louie35
is the image uploaded biger than the new size you are trying to onvert it to?
Re: Newbie question
Posted: Mon Apr 28, 2008 11:40 pm
by bebensiganteng
is the image uploaded biger than the new size you are trying to onvert it to?
Yes it does
Re: Newbie question
Posted: Tue Apr 29, 2008 8:28 am
by bebensiganteng
Guys... anybody knows the solution, pleasee

Re: Newbie question
Posted: Tue Apr 29, 2008 8:38 am
by mamad876
Hi,
First try to use
and then resize it in destination directory.
Re: Newbie question
Posted: Tue Apr 29, 2008 10:18 am
by pickle
Also, please wrap your PHP code in
tags.
Re: Image upload with Flash, resize with PHP
Posted: Wed Apr 30, 2008 2:26 am
by bebensiganteng
~pickle | Please use [ code=html ], [ code=php ], etc tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:
Posting Code in the Forums to learn how to do it too.
Hi Guys
Everah | Please use descriptive titles when posting in the forums. I have edited your post title to show it like we would like to see it.
Also, please wrap your PHP code in tags.
I'm very sorry for my mistakes it was really unintended and thank you for correcting them
and as for the problem, i've tried to move the file first and then resizing the image afterwards and it still doesnt work, below is the code
Code: Select all
$imageDirectory = "Common/Media/Images";
// EXECUTING
//-------------------------------------------------------------------------
if(!is_dir($imageDirectory)) mkdir($imageDirectory, 0755);
$fileNames = $_FILES['Filedata']['name'];
$uniqueId = "Common/Media/Images/".$_GET['fileId'].".jpg";
$imageFile = $uniqueId;
move_uploaded_file($_FILES['Filedata']['tmp_name'], $imageFile);
chmod($imageFile, 0777);
// Get new sizes
list($width, $height) = getimagesize($_FILES['Filedata']['tmp_name']);
$newwidth = 640;
$newheight = 480;
// Load
$new = imagecreatetruecolor($newwidth, $newheight);
$source = imagecreatefromjpeg($_FILES['Filedata']['tmp_name']);
// Resize
imagecopyresized($new, $source, 0, 0, 0, 0, $newwidth, $newheight, $width, $height);
// Output
imagejpeg($new, $imageFile);
and this is the link to the phpinfo() maybe it might help, because I personally dont understand it
http://www.iprox.net/snickers/cfb/info.php
Thanks again for the replies
~pickle | Please use [ code=html ], [ code=php ], etc tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:
Posting Code in the Forums to learn how to do it too.
Re: Image upload with Flash, resize with PHP
Posted: Wed Apr 30, 2008 9:51 am
by pickle
bebensiganteng wrote:I'm very sorry for my mistakes
If you're sorry, don't do it again.
What part isn't working? The file moving part? The image resizing part.
Incidentally, if you can, use image_copy_resampled() rather than image_copy_resized(). The former gives you a much better quality than the latter.
Re: Image upload with Flash, resize with PHP
Posted: Thu May 01, 2008 8:58 am
by bebensiganteng
If you're sorry, don't do it again.
no i wont
What part isn't working? The file moving part? The image resizing part.
The image resizing part