Link to home
Create AccountLog in
Avatar of LeighJor
LeighJorFlag for Afghanistan

asked on

PHP Need Quickly. Something wrong with calling 'define()' , creating file not directory

Hi  i think the synatx is incorrect when i use the define constant to create a thumbnail in a directory. I have:

define('THUMBS_DIR', 'c:\htdocs\test\ ' );
.......
then later:
$success = imagejpeg($thumb, THUMBS_DIR.$name.'_thb.jpg', 50);
                $thumb_name = $name.'_thb.jpg';
Which is only craeting file called THUMBS_DIR_thb.jpg not  a file named $name.'_thb.jpg' in folder THUMBS_DIR
Thanks in advance
leighjor
Avatar of hielo
hielo
Flag of Wallis and Futuna image

It sounds like $name is empty. Verify the its value. Where are you setting/getting its value from?
In addition, is that the exact define call you are using? There is a space after the last \ in 'c:\htdocs\test\ ', try:

define("THUMBS_DIR", "c:\htdocs\test\");
Avatar of LeighJor

ASKER

Hi LordOfPorts for some reason it gives syntax error if  no space.
$name = basename($newName, '.jpg');
I  soughta have a hunch that  
$success = imagejpeg($thumb, THUMBS_DIR.$name.'_thb.jpg', 50);
is not written correctly?
Cheers
SOLUTION
Avatar of hielo
hielo
Flag of Wallis and Futuna image

Link to home
membership
Create an account to see this answer
Signing up is free. No credit card required.
Create Account
I did that hielo and got

Use of undefined constant UPLOAD_DIR - assumed 'UPLOAD_DIR' in C:\htdocs\jim\phpsolutions\downloads\ch08\create_both_new.inc.php on line 53

line 53 is $newName = getNextFilename5( UPLOAD_DIR, $name, $t);


also got
Warning: imagejpeg() [function.imagejpeg]: Unable to open 'c:\htdocs\jim\phpsolutions\downloads\ch08\upload\_thb.jpg' for writing: No such file or directory in C:\htdocs\jim\phpsolutions\downloads\ch08\create_both_new.inc.php on line 122
 
Cheers
From what I posted, you are defining THUMBS_DIR not UPLOAD_DIR. You need to define UPLOAD_DIR to whatever is your upload directory or you could try changing line 53 to:
line 53 is $newName = getNextFilename5( THUMBS_DIR, $name, $t);

Did as you said  just a copy paste error now getting this message:

Warning: imagejpeg() [function.imagejpeg]: Unable to open 'c:\localhost\jim\phpsolutions\downloads\ch08\upload\thumb\images001_thb.jpg' for writing: No such file or directory in C:\htdocs\jim\phpsolutions\downloads\ch08\create_both_new.inc.php on line 122

images001.jpg successfully uploaded; Problem creating thumbnail

UPLOAD_DIR is defined in anoother page
 define("UPLOAD_DIR", "c:\\htdocs\\jim\\phpsolutions\\downloads\\ch08\\upload\\");
which upoloads image as

then this page should create thumbnails
define("THUMBS_DIR", "c:\\localhost\\jim\\phpsolutions\\downloads\\ch08\\upload\\thumb\\");

cheers & thanks so far
ASKER CERTIFIED SOLUTION
Link to home
membership
Create an account to see this answer
Signing up is free. No credit card required.
Create Account