Closed Thread Icon

Topic awaiting preservation: Function to upload images Pages that link to <a href="https://ozoneasylum.com/backlink?for=12509" title="Pages that link to Topic awaiting preservation: Function to upload images" rel="nofollow" >Topic awaiting preservation: Function to upload images\

 
Author Thread
Wakkos
Maniac (V) Mad Scientist

From: Azylum's Secret Lab
Insane since: Oct 2000

posted posted 11-17-2002 11:40

Hello!
I have this piece of code to upload files:

[code]
//begin upload 1

//checks if file exists
if ($img1_name == "") {
$log .= "<br>No file selected for upload 1<br>";
}
if ($img1_name != "") {
//checks if file exists

//checks if files to big
if (($sizelim == "yes") && ($img1_size > $size)) {
$log .= "Archivo muy grande";

} else {
$img1_name = strtolower($img1_name);
$img1_name = ereg_replace( " ", "", $img1_name);
//Checks if file is an image

if (($img1_type == $cert1) or ($img1_type == $cert2)) {
@copy($img1, "$abpath/$img1_name") or $log .= "No se pudo copiar la imagen al servidor<br>";

if (file_exists("$abpath/$img1_name")) {
$log .= "weeeeeee";
}

} else {
$log .= "File 1 is not an image<br>";
}
}
}
echo $log;
[code]

Which works cool, but if I want to make a function - function upload($imagename) - doesn't work.


What I'm doing is the following: input to choose how many image are you going to upload.
Then

code:
$num = 1;
while ($num <= $imgq ) {
echo "imagen #".$num." <input type=file name=img".$num." size=30><br>";
$num++;
}



Prints the inputs file depending on how many images he choose, and I want to make the upload function above to work as many times as images are upload or choosen, I can do it with only one image, but when I try to make it a functio to then make a while to porccess all the image, it doesn't work.


What I have now is:

function upload($img1){
code above
}

upload ($imagen1);

Of course, I changed the input file name to imagen".$num."

error: No file selected for upload 1
That means that $img1_name == ""


Anybody has time to take a look?
Thanks in advance!



Wakkos
follow the white rabbit

stinx
Bipolar (III) Inmate

From: London, UK
Insane since: Apr 2002

posted posted 11-18-2002 16:36

It seems you're only passing one of the variables to the function...

$img_name, $img_size etc are seperate variables that happen to be set in the global namespace.

Try using the $_FILES superglobal (if you have an up-to-date enough php version) and you shouldn't get this problem.

Wakkos
Maniac (V) Mad Scientist

From: Azylum's Secret Lab
Insane since: Oct 2000

posted posted 11-18-2002 18:41

Thank you stinx
That was exactly what was happening!!!!

« BackwardsOnwards »

Show Forum Drop Down Menu