Click to See Complete Forum and Search --> : Canīt find the problem


Perfidus
11-10-2003, 05:55 AM
Why it is giving me an error, everything seems to be ok???
I'm trying to upload a picture from a form and theis is the php to which form action is related to:


<?php
echo $envio1;
$refnum = $envio1;
$path = "fotos/";
$max_size = 200000;
if (!isset($HTTP_POST_FILES['userfile'])) exit;
if (is_uploaded_file($HTTP_POST_FILES['userfile']['tm
p_name'])) {
if ($HTTP_POST_FILES['userfile']['size']>$max_size) { echo "La foto es demasiado grande\n";
exit; }
if (($HTTP_POST_FILES['userfile']['type']=="image/gif") || ($HTTP_POST_FILES['userfile']['type']=="image/pjpeg") || ($HTTP_POST_FILES['userfile']['type']=="image/jpeg")) {
if (file_exists($path . $HTTP_POST_FILES['userfile']['name'])) { echo "Este nombre de archivo ya existe\n"; exit; }
$res = copy($HTTP_POST_FILES['userfile']['tmp_name'], $path.$refnum);
if (!$res) { echo "Envio de imagen fallido<br>\n"; exit; } else { echo "La imagen ha sido enviada<br>\n"; }
echo "Nombre de la foto: ".$HTTP_POST_FILES['userfile']['name']."\n";
echo "Tamaņo de la foto: ".$HTTP_POST_FILES['userfile']['size']." bytes\n";
echo "Tipo de archivo: ".$HTTP_POST_FILES['userfile']['type']."\n";
} else { echo "Este archivo no es un archivo JPG o GIF\n";
exit; }
}
?>


The error:
Warning: copy(fotos/): failed to open stream: Is a directory in /chs/p1/costa4seasons.com/home/html/imageupload3.php on line 12

pyro
11-10-2003, 07:21 AM
Did you CHMOD the directory to allow write access?

Perfidus
11-10-2003, 08:03 AM
what???
I'm almost sure this script was working the other day, In fact I was doing some proves and it worked out.
Nut now it doesn't work anymore.
What is to CHMOD?

pyro
11-10-2003, 10:25 AM
CHMOD is what you use to set the permissions for a file/directory. Most FTP clients should allow you to do this, so consult the help files to see how. Once you find out how to do it, CHMOD the directory that the images will be uploaded to to 755.

Perfidus
11-10-2003, 10:31 AM
I have use this:

chmod ("/fotos/"$userfile, 01777);
But I'm afraid it doesn't work.
It gives me an error itself.
By this way I'm chmod both directory and file, maybe there's a way only to chmod directory??

pyro
11-10-2003, 10:46 AM
I would not use PHP to do this, but rather your FTP program. You'll have a much better chance of being sucessful. Also, just as a side note, the mode parameter for chmod() takes only 4 digits.

Perfidus
11-10-2003, 10:58 AM
I'm developing an upload interface for customers, I can't suggest them to download, install and learn how to use a FTP program.

Perfidus
11-10-2003, 11:27 AM
I've just talk to my internet provider and they say I should not need to change CHMOD for doing what I'm doing so mistake should be somewhere else.
Pyro if you want to help I will thank you a lot, I try also to help those who are under my level and I have some good skills in flash and I help also in different forums like WH.
The idea of FTP program is obviously not what I'm trying to find, I'm using CUTE since 1997 more or less and now Smart FTP because it's free.

pyro
11-10-2003, 11:40 AM
I'm still inclined to believe that you will need to CHMOD the directory. Please try CHMODing the fotos directory to 777 and retry your script. A google seach found this (http://jewelz.star-gazers.net/chmoding_smartFTP.htm).

DaiWelsh
11-11-2003, 10:52 AM
if (file_exists($path . $HTTP_POST_FILES['userfile']['name'])) { echo "Este nombre de archivo ya existe\n"; exit; }
$res = copy($HTTP_POST_FILES['userfile']['tmp_name'], $path.$refnum);


In this snippet you test to see if a file with the uploaded file's name exists in the target directory

($path . $HTTP_POST_FILES['userfile']['name'])

but then when you try the copy you use

$path.$refnum

as the path to copy to. This is illogical and may well be the cause of your error, if $refnum is not suitable initialised.

HTH,

Dai