Page 1 of 1

problem w/ image upload

Posted: Sat Jun 03, 2006 4:39 pm
by alexus
Ok,
I went crazy here, I want to upload image and I used code that was working fone im my other project but now it aint working... :-(

it gives me this error:

Code: Select all

Warning: move_uploaded_file(../img_banners//tmp/phprzLkfI_a34230bc61b18538024986d442e6b45b.jpg): failed to open stream: No such file or directory in /usr/local/psa/home/vhosts/lrcommunications.net/httpdocs/uc/admin/frontpage_banner.php on line 89

Warning: move_uploaded_file(): Unable to move '/tmp/phprzLkfI' to '../img_banners//tmp/phprzLkfI_a34230bc61b18538024986d442e6b45b.jpg' in /usr/local/psa/home/vhosts/lrcommunications.net/httpdocs/uc/admin/frontpage_banner.php on line 89
Error uploading file
I see thta pemission denied, but tempdatafile should have proper permissions because it works on diferent project, and i set all users to have write read and execute permissions for the final directory. I was tying to run it on both Win/ Apache and FreeBSD/ Apache nothing is working

Can some one help?

Here is the code:

Code: Select all

if(isset($get_banner)|| isset($send_file)){
	if(isset($send_file)){
     	$uploaddir = '../img_banners/';
		$uploadfile = $uploaddir . basename($_FILES['userfile']['name']);
		$ext = substr(strrchr($_FILES['userfile']['name'], '.'), 1);
		$new_name = $userfile. "_". md5($userfile).".$ext";
		if (move_uploaded_file($_FILES['userfile']['tmp_name'], "../img_banners/".$new_name)) {
		   echo "File uploaded";
		} else {
		   echo "Error uploading file";
		}
    }
	?>
    <form method="POST" enctype="multipart/form-data" action="<? echo $PHP_SELF; ?>">
	<div align="center">
		<div align="center">
			<b><? echo $event; ?></b><br>
            <table border="0" width="419" style="border-collapse: collapse">
				<tr>
					<td colspan="2" bgcolor="#008080">
					<p align="center"><b>
					<font face="Arial" size="2" color="#FFFFFF">Already Uploaded</font></b></td>
				</tr>
				<tr>
					<td width="141" bgcolor="#C0C0C0">File Name: </td>
					<td width="262" bgcolor="#C0C0C0">&nbsp;</td>
				</tr>
				</table>
		</div>
		<br>
		<table border="0" width="419" style="border-collapse: collapse">
			<tr>
				<td colspan="2" bgcolor="#008080">
				<p align="center"><b>
				<font size="2" face="Arial" color="#FFFFFF">Upload Front Page 
				Banner</font></b></td>
			</tr>
			<tr>
				<td width="141" bgcolor="#C0C0C0">Select File: </td>
				<td width="262" bgcolor="#C0C0C0"><input type="file" name="userfile" size="20"></td>
			</tr>
			<tr>
				<td width="141" bgcolor="#C0C0C0">&nbsp;</td>
				<td width="262" bgcolor="#C0C0C0"><input type="submit" name="send_file" value="Upload Banner"></td>
			</tr>
		</table>
	</div>
    <input type="hidden" name="event" value="<? echo $event; ?>">
    <input type="hidden" name="event_id" value="<? echo $event_id?>">
</form>
    <?
}
?>

Posted: Sat Jun 03, 2006 5:06 pm
by ok
Change uploaddir to:

Code: Select all

$uploaddir = '../img_banners';
(without the last "/")
And you may post your question in the PHP code forum, there you will find more help!

Posted: Sat Jun 03, 2006 5:17 pm
by alexus
that doesnt work

Posted: Sat Jun 03, 2006 5:34 pm
by Christopher
Is this a valid path on your system? Can you give us the output when you do :

Code: Select all

ls -al /usr/local/psa/home/vhosts/lrcommunications.net/httpdocs/uc/admin/

Posted: Sat Jun 03, 2006 6:52 pm
by alexus
arborint, is that comand line or a php comman? i cant even get thay line to give any reasonable output

Posted: Sat Jun 03, 2006 9:10 pm
by alexus
arborint, yea the problem is in the path... I dono yet how to resolve it though but what I did was created sub folder img/ and changed the line w/ new name to

Code: Select all

if (move_uploaded_file($_FILES['userfile']['tmp_name'], "img/test.jpg")) {
well it works, let me debug it to make it work un upper level subfolder and dynamic name

Posted: Sat Jun 03, 2006 9:36 pm
by alexus
ok here is the answer to my question :
the problem is in this line

Code: Select all

$new_name = $userfile. "_". md5($userfile).".$ext";
it generates twong path... I have no idea how it worked before... but it generates something likethis
img/C://windows/Apache/httpd

Posted: Sat Jun 03, 2006 10:16 pm
by hawleyjr
Moved to PHP Code