Relative path and image variable concatenation not working

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
Suzanne
Forum Newbie
Posts: 10
Joined: Thu Nov 15, 2007 4:18 pm

Relative path and image variable concatenation not working

Post by Suzanne »

feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]


Hi guys,

I have an upload form upload_form.html with a browse button and a field for the image name. The image is retrieved and saved with upload.php which calls test.cropinterface.php so the user can crop and save the uploaded image. However, when I pass the image variable from upload.php to test.cropinterface.php by $_GET['filename'], the filename will be displayed when I use echo $filename, but when I try to use a save or copy function, the error message lets me know that it cannot recognize an empty string. Please see my code for test.cropinterface.php below. Global variables is on and I am using a newer version of php.

Code: Select all

<?php

header("Pragma: no-cache");
header('cache-control: no-store, must revalidate');

require('class.cropinterface.php')
$ci =& new CropInterface(true);

//this pass and variable call works

$filename=$_GET['filename'];
echo $filename;

if(isset($_GET['file'])
{
$ci->loadImage($_GET['file'];
//this pass and variable call does not work, but loadImage function does
//$filename=$_GET['filename'];
//echo $filename;
$ci->cropTo Dimensions($GET_['sx']. $GET_['sy'], $GET_['ex'], $GET_['ey']);

//this works and saves the cropped image to a relative path
$ci->saveImage("images/cropped.jpg", 100);

//this does not work and the error message states that it can't recognize filetype '../../Images/Thumbnails/Assemblages_Thumbs/'. 


$ci->saveImage("../../Images/Thumbnails/Assemblages_Thumbs/".$filename, 100);
// I also tried 
//$ci->saveImage("../../Images/Thumbnails/Assemblages_Thumbs/$filename",100);
//or
//copy("images/cropped.jpg", "../../Images/Thumbnails/Assemblages_Thumbs/".$filename);

}
?>
I guess the error means that the variable must be empty. However if I put "../../Images/Thumbnails/Assemblages_Thumbs/new.jpg" instead of "../../Images/Thumbnails/Assemblages_Thumbs/".$filename it works
I have been trying to get my head through this wall for the past 2 weeks. Its only gotten my headaches. So it would be soo great if someone would see what I am doing wrong here.


feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]
sunilbhatia79
Forum Newbie
Posts: 24
Joined: Sun Nov 11, 2007 9:37 pm
Location: Mumbai, India

Post by sunilbhatia79 »

Check this tutorial on file uploads:

http://www.w3schools.com/php/php_file_upload.asp
Suzanne
Forum Newbie
Posts: 10
Joined: Thu Nov 15, 2007 4:18 pm

Post by Suzanne »

Thanks suni,

Sorry for using the CODE instead of the PHP tag. I visit the w3 websites often to look for tutorials, but I actually know how to save an uploaded file. This time I couldn't find any help or code samples for this specific problem. Maybe if I provide more code you can understand better.

upload_form.html

Code: Select all

<form name="browse" enctype="multipart/form-data" method="post" action="upload.php?nocache='.time().'">
          <input type="hidden" value="100000" name="MAX_FILE_SIZE">
          <input name="uploaded" type="file" size="50" >
     //user chooses which folders the images will be saved to by selecting the appropriate checkboxes
          <input name="assemblages" type="checkbox" id="assemblages" value="assemblages">Assemblages
          <input name="collaborations" type="checkbox" value="collaborations">Collaborations
          <input name="jazz" type="checkbox" value="jazz">Jazz_Icons</div></td>
          <input name="paintings" type="checkbox" value="paintings">Paintings
          <input name="paper" type="checkbox" value="paper">Paper
          <input name="new_art" type="checkbox" value="new_art" checked>New Art Work            
      //user submits the form
          <input name="submit" type="submit" value="Upload...">       
</form>

upload_form.html calls upload.php

Code: Select all

<?php

$filename = basename($_FILES['uploaded']['name']); 

//... some other code

switch($mimetype) {
case "image/jpg":
case "image/jpeg":
case "image/pjpeg":$ok=1;
break;
case "image/gif": $ok=1;
break;
case "image/png": $ok=1;
break;
}

//Here we check that $ok was not set to 0 by an error
if ($ok==0)
{
echo "Sorry your file was not uploaded<br>";
}
//If everything is ok we try to upload it to different folders and to uploaded_image.jpg
//This works perfectly
if($ok==1)
{
	$uploadfile="./Image_Upload/cropcanvas/images/uploaded_image.jpg";
	move_uploaded_file($_FILES['uploaded']['tmp_name'], $uploadfile);

}

///*********************
///THIS IS THE CRUCIAL QUESTION. Am I doing something wrong when I pass $filename to test.cropinterface.php (please see first post)
///**********************
header("location:Image_Upload/cropcanvas/test.cropinterface.php?filename=$filename". "&assem=$assem_folder&collab=$collab_folder&jazz=$jazz_folder&". "paint=$paint_folder&paper=$paper_folder&new=$new_folder");
?>
As said before I can echo the filename when I fetch $filename in test.cropinterface.php, but I cannot save it with my save() or copy() function, which I know have worked before. The variable appears to be empty. Could it be that other uses of $_GET (e.g. $_GET['file']) alter the assigned $filename variable?[/list]
User avatar
s.dot
Tranquility In Moderation
Posts: 5001
Joined: Sun Feb 06, 2005 7:18 pm
Location: Indiana

Post by s.dot »

Code: Select all

$ci->cropTo Dimensions($GET_['sx']. $GET_['sy'], $GET_['ex'], $GET_['ey']);
You have a space in your method call. Shouldn't it be cropToDimensions?
Set Search Time - A google chrome extension. When you search only results from the past year (or set time period) are displayed. Helps tremendously when using new technologies to avoid outdated results.
User avatar
s.dot
Tranquility In Moderation
Posts: 5001
Joined: Sun Feb 06, 2005 7:18 pm
Location: Indiana

Post by s.dot »

And your $GET_ variables should be $_GET (underscore before GET)
Also, I believe that should be a comma (,) and not a period (.) after $_GET['sx'] parameter of that method.
Set Search Time - A google chrome extension. When you search only results from the past year (or set time period) are displayed. Helps tremendously when using new technologies to avoid outdated results.
Suzanne
Forum Newbie
Posts: 10
Joined: Thu Nov 15, 2007 4:18 pm

Post by Suzanne »

Code: Select all

php: 
$ci->cropTo Dimensions($GET_['sx']. $GET_['sy'], $GET_['ex'], $GET_['ey']);



You have a space in your method call. Shouldn't it be cropToDimensions?

That function actually works. I got the class and script from Andrew Collington http://www.phpclasses.org. Its a great little script and brought me only joy and happiness. :D

However, something is wrong with my variable, because I cannot even copy with the regular copy() function from an existing file to the path + filename variable.

I really appreciate all the help.
Suzanne
Forum Newbie
Posts: 10
Joined: Thu Nov 15, 2007 4:18 pm

Post by Suzanne »

Code: Select all

php: 
$ci->cropTo Dimensions($GET_['sx']. $GET_['sy'], $GET_['ex'], $GET_['ey']);



You have a space in your method call. Shouldn't it be cropToDimensions?

That function actually works. I got the class and script from Andrew Collington http://www.phpclasses.org. Its a great little script and brought me only joy and happiness. :D

However, something is wrong with my variable, because I cannot even copy with the regular copy() function from an existing file to the path + filename variable.

I really appreciate all the help.
Suzanne
Forum Newbie
Posts: 10
Joined: Thu Nov 15, 2007 4:18 pm

Post by Suzanne »

Oops,

It was just a typo. I didn't have my original script at work, so I had to retype to post this in this forum. So yes

Code: Select all

php: 
$ci->cropTo Dimensions($GET_['sx']. $GET_['sy'], $GET_['ex'], $GET_['ey']);
should be...

Code: Select all

php: 
$ci->cropTo Dimensions($_GET['sx']. $_GET['sy'], $_GET['ex'], $_GET['ey']);
Unfortunately, the script is still not working.
Post Reply