Page 1 of 1

problems with file upload

Posted: Fri Jul 11, 2003 8:35 pm
by conundrum
I have a routine that uploads a selection of images from a form and then inserts the details of the record. It works flawlessly.

I then have a change routine which allows me to add more images or change existing images or details etc... I can change details with no trouble but when I try to change an image or add another image it refuses to upload the file. I could understand if it only happened when I tried to change an image and it couldn't overwrite the existing one, but it doesn't work when I try to upload another image with another name.

So... when I add a new record with an image, it says
/tmp/phpjT6HpK
Slide 1 was successfully uploaded!

And when I try to add another image to the record and upload it it says
F:\\www\\images\\hack1.jpg
Slide 2 could not be copied

It appears that when it is a new record being added, it uploads the file to a temp directory on my hosts server, and when I try to add a new image it says the source is on my F: drive.

I have read every post about uploads and am stumped, can anyone help?

Posted: Fri Jul 11, 2003 9:22 pm
by phice
Could you post your code?

Posted: Fri Jul 11, 2003 10:13 pm
by conundrum
I figured you might like to see some code. I have TONS of code that repeats, allowing up to 16 slides for a slideshow etc...

I have included the function that does the upload and the forms for each routine as well as the php from each routine.

If you need more I can try to post more, but the files are quite large.

Code: Select all

<?php
//A COMMON FUNCTION TO BOTH THE ADD AND CHANGE PAGES
//A FUNCTION TO UPLOAD THE SLIDE IMAGE
function upload($img, $name, $f){
	if(move_uploaded_file($img, "../images/".$name.$f.".jpg")){
		print_r($img);
		echo("<br><font color=#336699>Slide $f was successfully uploaded!</font><p>\n");
	}else{
		print_r($img);
		echo("<br><font color=#CC0000>Slide $f could not be copied</font><p>\n");
	}
	unlink($img);
}

//ON THE ADD FORM
<form action=added.php method=post ENCTYPE=multipart/form-data>
	<input type=file name=slide1 size=40>
	<input type=submit value=Add>
</form>

//IN THE ADDED.PHP FILE WHERE THE WORK IS DONE
if($slide1){
	$f=1;	//a counter
	upload($slide1, $image, $f);
}

//ON THE CHANGE FORM
<FORM method=post action=change3.php>
	<input type=file name=slide1 size=20>
	<input type=submit value=Change> </td>
</form>

//IN THE CHANGE3.PHP FILE
$newSlideshow = $slideshow;
if($slide1){
	$f=1;
	upload($slide1, $image, $f);
	if($f<=$slideshow){
		//nochange to slideshow count
	}else{
		$newSlideshow++;
	}
}
?>