Image upload with Flash, resize with PHP

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
bebensiganteng
Forum Newbie
Posts: 23
Joined: Wed Jan 03, 2007 6:03 am
Location: UAE

Image upload with Flash, resize with PHP

Post 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
Last edited by RobertGonzalez on Tue Apr 29, 2008 11:56 am, edited 1 time in total.
Reason: Edited the title so it wasn't so vague.
User avatar
aceconcepts
DevNet Resident
Posts: 1424
Joined: Mon Feb 06, 2006 11:26 am
Location: London

Re: Newbie question

Post 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().
bebensiganteng
Forum Newbie
Posts: 23
Joined: Wed Jan 03, 2007 6:03 am
Location: UAE

Re: Newbie question

Post 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
User avatar
louie35
Forum Contributor
Posts: 144
Joined: Fri Jan 26, 2007 8:40 am
Location: Dublin
Contact:

Re: Newbie question

Post by louie35 »

is the image uploaded biger than the new size you are trying to onvert it to?
bebensiganteng
Forum Newbie
Posts: 23
Joined: Wed Jan 03, 2007 6:03 am
Location: UAE

Re: Newbie question

Post by bebensiganteng »

is the image uploaded biger than the new size you are trying to onvert it to?
Yes it does
bebensiganteng
Forum Newbie
Posts: 23
Joined: Wed Jan 03, 2007 6:03 am
Location: UAE

Re: Newbie question

Post by bebensiganteng »

Guys... anybody knows the solution, pleasee :cry:
mamad876
Forum Newbie
Posts: 6
Joined: Wed Mar 22, 2006 1:59 pm

Re: Newbie question

Post by mamad876 »

Hi,

First try to use

Code: Select all

move_uploaded_file()
and then resize it in destination directory.
User avatar
pickle
Briney Mod
Posts: 6445
Joined: Mon Jan 19, 2004 6:11 pm
Location: 53.01N x 112.48W
Contact:

Re: Newbie question

Post by pickle »

[url=http://forums.devnetwork.net/viewtopic.php?t=30037]Forum Rules[/url] Section 1.1 wrote:2. Use descriptive subjects when you start a new thread. Vague titles such as "Help!", "Why?" are misleading and keep you from receiving an answer to your question.
Also, please wrap your PHP code in tags.
Real programmers don't comment their code. If it was hard to write, it should be hard to understand.
bebensiganteng
Forum Newbie
Posts: 23
Joined: Wed Jan 03, 2007 6:03 am
Location: UAE

Re: Image upload with Flash, resize with PHP

Post 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: :arrow: 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: :arrow: Posting Code in the Forums to learn how to do it too.
User avatar
pickle
Briney Mod
Posts: 6445
Joined: Mon Jan 19, 2004 6:11 pm
Location: 53.01N x 112.48W
Contact:

Re: Image upload with Flash, resize with PHP

Post 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.
Real programmers don't comment their code. If it was hard to write, it should be hard to understand.
bebensiganteng
Forum Newbie
Posts: 23
Joined: Wed Jan 03, 2007 6:03 am
Location: UAE

Re: Image upload with Flash, resize with PHP

Post 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
Post Reply