Click to See Complete Forum and Search --> : 4 days fighting against it!!


Perfidus
11-13-2003, 02:25 PM
This is the code I'm using for uploading a picture to my website:

echo "FICHIER=$file<br>\n"; //gives the temporary name of our file
echo "TMP=$file_tmp<br>\n"; // same as $file.
echo "TYPE=$file_type<br>\n"; // gives the MIME type of our file (image/jpeg or image/gif)
echo "NAME=$file_name<br>\n"; //gives the name of the uploaded file

$repertoire = "temp/"; // path to the temp directory
$repertoire2 = "img/"; // path to the image directory
$destination = $repertoire2.$file_name; //destination of the file img/filename.jpg

echo "TEXTE=$pic_comment<br>\n"; //print our picture description - this is what we have written in the form (textarea name="pic_comment")
echo "TEXTE=$pic_title<br>\n"; //print the title of our picture (input type="text" name="pic_title")
if (!move_uploaded_file($file, $destination)) {echo "ERROR: Impossible to move the file: $file to $destination";} //file is moved from temp to img
$file = "/www.costa4seasons.com/picture/img/" . $file_name; //this should be the absolute path to your uploaded file
$split = split(".", $file);
$name = $split[0];
$image = ImageCreateFromJPEG($file); //copy of the uploaded image
$width = imagesx($image) ; //size verification
$height = imagesy($image) ; //size verification

$new_width = 50; //we specify the width for our thumbnail... here 50 pixel
$new_height = ($new_width * $height) / $width ; // get the apropriate height

$thumb = imagecreate($new_width,$new_height); // creation of a white 50 pixel wide thumb

imagecopyresized($thumb,$image,0,0,0,0,$new_width,
$new_height,$width,$height); // thumb is now created on the white canvas

ImageJPEG($thumb, $name."_thumb.jpg"); // gives the MIME type to the file (jpeg, gif or png) and add _thumb.jpg to the file name.

imagedestroy($image); // destroy our copy of the uploaded image

?>



And those are all the errors I get:



FICHIER=/tmp/phpuXw2ef
TMP=
TYPE=image/pjpeg
NAME=feo7varios.jpg
TEXTE=wgg yheytjhety tyejejej teyjej
TEXTE=guapo

Warning: move_uploaded_file(/www.costa4seasons.com/picture/img/feo7varios.jpg): failed to open stream: No such file or directory in /chs/p1/costa4seasons.com/home/html/picture/upload_process.php on line 13

Warning: move_uploaded_file(): Unable to move '/tmp/phpuXw2ef' to '/www.costa4seasons.com/picture/img/feo7varios.jpg' in /chs/p1/costa4seasons.com/home/html/picture/upload_process.php on line 13
ERROR: Impossible to move the file: /tmp/phpuXw2ef to /www.costa4seasons.com/picture/img/feo7varios.jpg
Warning: imagecreatefromjpeg(/www.costa4seasons.com/picture/img/feo7varios.jpg): failed to open stream: No such file or directory in /chs/p1/costa4seasons.com/home/html/picture/upload_process.php on line 19

Warning: imagesx(): supplied argument is not a valid Image resource in /chs/p1/costa4seasons.com/home/html/picture/upload_process.php on line 20

Warning: imagesy(): supplied argument is not a valid Image resource in /chs/p1/costa4seasons.com/home/html/picture/upload_process.php on line 21

Warning: Division by zero in /chs/p1/costa4seasons.com/home/html/picture/upload_process.php on line 24

Warning: imagecreate(): Invalid image dimensions in /chs/p1/costa4seasons.com/home/html/picture/upload_process.php on line 26

Warning: imagecopyresized(): supplied argument is not a valid Image resource in /chs/p1/costa4seasons.com/home/html/picture/upload_process.php on line 28

Warning: imagejpeg(): supplied argument is not a valid Image resource in /chs/p1/costa4seasons.com/home/html/picture/upload_process.php on line 30

Warning: imagedestroy(): supplied argument is not a valid Image resource in /chs/p1/costa4seasons.com/home/html/picture/upload_process.php on line 32


I need help!

pyro
11-13-2003, 02:38 PM
You might not want to use register_globals (http://www.webdevfaqs.com/php.php#globalvariables), and have you look at http://us3.php.net/features.file-upload?

Perfidus
11-13-2003, 03:31 PM
I will take a closer look to this tutorial, and about globals, they seem to be ON because they are giving me some feedback.
Why I shouldn't use them?
Will this code work one day?

Perfidus
11-13-2003, 04:56 PM
Pyro, I agree we are generally lazy and we do not check manuals but we go straight and try to do the things on the wild way (Cutting, Pasting, Replacing) but have U ever consideer the possibility that sometimes we are not able to find a very stupid problem?
Not even if we read all the manuals in world.
Your advice is fine, but sometimes too short for newbies.

I have already read your links, and now I'm like allways stuck on an dead end road.

pyro
11-13-2003, 05:25 PM
I link to the manual often because often times, that's all it takes to solve people's problems. Apart from that, it is the definitive guide to PHP.

Anyway, try changing this:

if (!move_uploaded_file($file, $destination)) {echo "ERROR: Impossible to move the file: $file to $destination";} //file is moved from temp to img

to:

if (!move_uploaded_file($file, $destination)) {echo "ERROR: Impossible to move the file: $file to $destination";} //file is moved from temp to img And make sure the img dir that you are uploading to is CHMODed to 777 (or perhaps 666).

Perfidus
11-13-2003, 07:47 PM
Thanks a lot, but, I have been looking at the line I should replace and the one U gave me, and I find them completely the same. Maybe there's some mistake?
Abot CHMODING I do not think I need it cause I can upload whatever without any change.

ORIGINAL LINE:
if (!move_uploaded_file($file, $destination)) {echo "ERROR: Impossible to move the file: $file to $destination";} //file is moved from temp to img

The line U suggested:
if (!move_uploaded_file($file, $destination)) {echo "ERROR: Impossible to move the file: $file to $destination";} //file is moved from temp to img

pyro
11-13-2003, 09:18 PM
My bad :rolleyes:

Try this one:

if (!move_uploaded_file($file_tmp, $destination)) {echo "ERROR: Impossible to move the file: $file to $destination";} //file is moved from temp to img

Perfidus
11-14-2003, 03:17 AM
What I have seen:

The line

if (!move_uploaded_file($file, $destination)) {echo "ERROR: Impossible to move the file: $file to $destination";} //file is moved from temp to img

Works actually because I can find the uploaded picture in dir img/ when I upload the picture, so it should go to tmp/ and after is moved to img/

The problems seem to come after, in next lines:



Warning: imagecreatefromjpeg(www.costa4seasons.com/img/feo7varios.jpg): failed to open stream: No such file or directory in /chs/p1/costa4seasons.com/home/html/upload_process.php on line 18

Warning: imagesx(): supplied argument is not a valid Image resource in /chs/p1/costa4seasons.com/home/html/upload_process.php on line 20

Warning: imagesy(): supplied argument is not a valid Image resource in /chs/p1/costa4seasons.com/home/html/upload_process.php on line 21

Warning: Division by zero in /chs/p1/costa4seasons.com/home/html/upload_process.php on line 23

Warning: imagecreate(): Invalid image dimensions in /chs/p1/costa4seasons.com/home/html/upload_process.php on line 24

Warning: imagecopyresized(): supplied argument is not a valid Image resource in /chs/p1/costa4seasons.com/home/html/upload_process.php on line 25

Warning: imagejpeg(): supplied argument is not a valid Image resource in /chs/p1/costa4seasons.com/home/html/upload_process.php on line 26

Warning: imagedestroy(): supplied argument is not a valid Image resource in /chs/p1/costa4seasons.com/home/html/upload_process.php on line 27

Perfidus
11-14-2003, 05:17 AM
Maybe I should fix error by error; for example spliting is not working I do not know why:

$split = split("/.", $file_name);
$name = $split[0];
$chemin= "img/".$name."_thumb.jpg";
$url_thumb="http://www.costa4seasons.com/".$chemin;
echo $url_thumb; // this will give you the complete url to your thumbnail

this give as a result when echoing this:
http://www.costa4seasons.com/img/feo7varios.jpg_thumb.jpg
so spliting for omiting extension is not working, any ideas?

pyro
11-14-2003, 07:16 AM
Yes, you used forward slash (/) to escape the full stop (period) when you should have used a backslash (\)


$split = split("\\.", $file_name);
$name = $split[0];

Perfidus
11-14-2003, 07:27 AM
This is the solution I have found for the split question:

$split = split('\.', $file_name);

The code has change a little bit:

<?
echo "FICHIER=$file<br>\n"; //gives the temporary name of our file
echo "TMP=$tmp_name<br>\n"; // same as $file.
echo "TYPE=$file_type<br>\n"; // gives the MIME type of our file (image/jpeg or image/gif)
echo "NAME=$file_name<br>\n"; //gives the name of the uploaded file
$repertoire = "temp/"; // path to the temp directory
$repertoire2 = "img/"; // path to the image directory
$destination = $repertoire2.$file_name; //destination of the file img/filename.jpg
echo "TEXTE=$pic_comment<br>\n"; //print our picture description - this is what we have written in the form (textarea name="pic_comment")
echo "TEXTE=$pic_title<br>\n"; //print the title of our picture (input type="text" name="pic_title")
if (!move_uploaded_file($file, $destination)) {echo "ERROR: Impossible to move the file: $file to $destination";} //file is moved from temp to img
//if (!move_uploaded_file($file_tmp, $destination)) {echo "ERROR: Impossible to move the file: $file to $destination";} //file is moved from temp to img
$file = "www.costa4seasons.com/img/" . $file_name; //this should be the absolute path to your uploaded file
$split = split('\.', $file_name);
//$name = explode(".",$file_name);
$name = $split[0];
//$name=substr($file_name,0,strrpos($file_name,".")-1)
$image = ImageCreateFromJPEG($file); //copy of the uploaded image
$width = imagesx($image) ; //size verification
$height = imagesy($image) ; //size verification
$new_width = 50; //we specify the width for our thumbnail... here 50 pixel
$new_height = ($new_width * $height) / $width ; // get the apropriate height
$thumb = imagecreate($new_width,$new_height); // creation of a white 50 pixel wide thumb
imagecopyresized($thumb,$image,0,0,0,0,$new_width,$new_height,$width,$height); // thumb is now created on the white canvas
ImageJPEG($thumb, $name."_thumb.jpg"); // gives the MIME type to the file (jpeg, gif or png) and add _thumb.jpg to the file name.
imagedestroy($image); // destroy our copy of the uploaded image
$chemin= "img/".$name."_thumb.jpg";
$url_thumb="http://www.costa4seasons.com/".$chemin;
echo $url_thumb; // this will give you the complete url to your thumbnail
echo "<img src='" . $url_thumb . "'><br>\n"; // print the thumbnail of the uploaded picture
?>

But still have errors (less at least):

FICHIER=/tmp/phpjLfA8q
TMP=
TYPE=image/pjpeg
NAME=feo7varios.jpg
TEXTE=yhy43hu 46u
TEXTE=gtg

Warning: imagecreatefromjpeg(www.costa4seasons.com/img/feo7varios.jpg): failed to open stream: No such file or directory in /chs/p1/costa4seasons.com/home/html/upload_process.php on line 18

Warning: imagesx(): supplied argument is not a valid Image resource in /chs/p1/costa4seasons.com/home/html/upload_process.php on line 19

Warning: imagesy(): supplied argument is not a valid Image resource in /chs/p1/costa4seasons.com/home/html/upload_process.php on line 20

Warning: Division by zero in /chs/p1/costa4seasons.com/home/html/upload_process.php on line 22

Warning: imagecreate(): Invalid image dimensions in /chs/p1/costa4seasons.com/home/html/upload_process.php on line 23

Warning: imagecopyresized(): supplied argument is not a valid Image resource in /chs/p1/costa4seasons.com/home/html/upload_process.php on line 24

Warning: imagejpeg(): supplied argument is not a valid Image resource in /chs/p1/costa4seasons.com/home/html/upload_process.php on line 25

Warning: imagedestroy(): supplied argument is not a valid Image resource in /chs/p1/costa4seasons.com/home/html/upload_process.php on line 26
http://www.costa4seasons.com/img/feo7varios_thumb.jpg

pyro
11-14-2003, 07:31 AM
Is this the root path to the image?

$file = "www.costa4seasons.com/img/" . $file_name; //this should be the absolute path to your uploaded file If not, it is not an absolute path either. You'd want:

$file = "http://www.costa4seasons.com/img/" . $file_name; //this should be the absolute path to your uploaded file

Perfidus
11-14-2003, 07:55 AM
Warning: imagecreatefromjpeg(http://www.costa4seasons.com/img/feo7varios.jpg): failed to open stream: HTTP request failed! HTTP/1.1 403 Forbidden in /chs/p1/costa4seasons.com/home/html/upload_process.php on line 18

Perfidus
11-14-2003, 08:03 AM
with the SMART FTP I can see that picture is there (have been copied to directory img/) but If I wrote this in my URL:
http://www.costa4seasons.com/img/feo7varios.jpg
It doesn't work.
WHY???

I'm getting crazy!

Perfidus
11-14-2003, 08:26 AM
If I upload a picture via PHP form it can not be seen (Even though I know it is there):
http://www.costa4seasons.com/img/DSCN1763.JPG
If I upload it via FTP, it can be seen:
http://www.costa4seasons.com/img/DSCN1762.JPG

Is this magic?
Has anyone an explanation?

GavinPearce
11-15-2003, 01:38 PM
Originally posted by Perfidus
Pyro, I agree we are generally lazy and we do not check manuals but we go straight and try to do the things on the wild way (Cutting, Pasting, Replacing)

I don't think that's being lazy. That's my favorite way of learning. Doing pratical stuff I learn, I'll forget the theory of it all in minutes.