GIDForums  

Go Back   GIDForums > Computer Programming Forums > MySQL / PHP Forum
User Name
Password
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read

 
 
Thread Tools Search this Thread Rate Thread
  #1  
Old 08-Jun-2004, 18:32
misunderstood misunderstood is offline
Member
 
Join Date: Jun 2003
Posts: 121
misunderstood is on a distinguished road

Writing image to folder


I have script that uploads an image to an image folder (obvious its an image folder) within the script folder. I now want to have the image folder outside of the script folder (and still write to it).
At the moment I use
Quote:
chdir("../imagefolder/subfolder/");

Now if I move the folder outside of my script folder I cannot work out what path I should use. I have tried lots of variations but cannot work it out. Can anybody help
  #2  
Old 09-Jun-2004, 18:05
misunderstood misunderstood is offline
Member
 
Join Date: Jun 2003
Posts: 121
misunderstood is on a distinguished road
Had a sleep and changed direction slightly.
So the last post is slightly null and void
I am using
Quote:
if($Pic1!="")
{
$size1 = $HTTP_POST_FILES['Pic1']['size'];
$pic1 = $HTTP_POST_FILES['Pic1']['name'];
$tmp_fname = $HTTP_POST_FILES['Pic1']['tmp_name'];

copy($tmp_fname, $pic1)
or die("Couldn't copy the file.");
}
to upload an image which works as previous post.
I now want to upload to a specified folder outside of this folder and also create a thumbnail of the image 150px in height (jpeg or gif) with the same name but say a prefix 't' (for thumb ) but the extension correct of course.
Now I have searched lots of different scripts to get this clear but I am still slightly confused. What I could do with is a pointer to a clear tutorial that explains what each section means and does. Can anybody assist.
  #3  
Old 10-Jun-2004, 08:43
JdS's Avatar
JdS JdS is offline
Senior Member
 
Join Date: Aug 2001
Location: KUL, Malaysia
Posts: 3,371
JdS will become famous soon enough
I don't know any tutorials but I have a few suggestions...

Use $_FILES instead of $HTTP_POST_FILES...

A simple example...

PHP Code:

<?php

// define the path to the upload folder
define( 'UPLOAD_DIR', '/home/username/public_html/scripts/images/' );

if( move_uploaded_file($_FILES['userfile']['tmp_name'], UPLOAD_DIR.$_FILES['userfile']['name']) )
{
    print "File is valid, and was successfully uploaded.  Here's some more debugging info:\n";
    echo '<pre>';
    print_r( $_FILES );
    echo '</pre>';
}
?>

  #4  
Old 17-Jun-2004, 08:03
misunderstood misunderstood is offline
Member
 
Join Date: Jun 2003
Posts: 121
misunderstood is on a distinguished road
I have solved the problem of uploading an image and creating a thumbnail using:
PHP Code:

if($Pic1 !="" )
    {    $size1 = $HTTP_POST_FILES['Pic1']['size'];
        $pic1 = $HTTP_POST_FILES['Pic1']['name'];
        $tmp_fname = $HTTP_POST_FILES['Pic1']['tmp_name'];
        
        copy($tmp_fname, $pic1)
        or die("Couldn't copy the file.");
                                if ($pic1_size<(1024*130))
                        {
                        
                    
                        $aNewName='h'.$pic1;
                        copy($pic1,$aNewName);
                        $imgsz=getimagesize($aNewName);
                        $width=$imgsz[0];
                        $height=$imgsz[1];
                        if ($width>$height)
                            {
                            $newwidth=130;
                            $newheight=$height*130/$width;
                            }
                        else
                            {
                            $newheight=130;
                            $newwidth=$width*130/$height;
                            }
                        $newim=imagecreatetruecolor($newwidth,$newheight);
                        $oldim=imagecreatefromjpeg($aNewName);
                        imagecopyresized($newim,$oldim,0,0,0,0,$newwidth,$newheight,$width,$height);
                        imagejpeg($newim,'h'.$pic1,70);
                        }
    }
    else
    $pic1=""; 



However I suspect the code is not quite right even tho it works. Maybe its just that I am having a little success I am getting nervous. Can anybody (JdS) confirm that the code is ok and is on par with the pile of gobbledy-gook that I normally write.
Last edited by JdS : 17-Jun-2004 at 08:14. Reason: please enclose your PHP codes in [PHP] and [/PHP] tags.
  #5  
Old 17-Jun-2004, 08:18
JdS's Avatar
JdS JdS is offline
Senior Member
 
Join Date: Aug 2001
Location: KUL, Malaysia
Posts: 3,371
JdS will become famous soon enough
Are you nuts? I am not going to look at code when there's a good game on tonight!? I need my nap now so I can stay awake in the middle of the night.

Just kidding, unfortunately "image" and "uploading" stuff in PHP is not my forte. Hope someone else can go through your code and suggest changes if any.
 
 

Recent GIDBlogAccepted for Ph.D. program by crystalattice

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Google Adsense introduces targetted image ads Div Advertising & Affiliates Forum 5 23-May-2004 11:59
Problem with image eRIC MySQL / PHP Forum 1 08-Apr-2004 07:22
writing into file prob belludandy C Programming Language 0 15-Nov-2003 20:25
professional quality image generator jrobbio Graphics Forum 0 27-May-2003 05:45
how to return an image with a .js file JdS Web Design Forum 5 24-Nov-2002 10:15

Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The

All times are GMT -6. The time now is 07:44.


vBulletin, Copyright © 2000 - 2009, Jelsoft Enterprises Ltd.