Jump to content

Recommended Posts

Im trying to just simply upload an image and the insert it into my database.  I have my code which I have stripped all error checking out.  When it runs the page refreshs but the file does not appear in the folder and the table is not updating.  There are no server log errors or anything can someone help please...

 

This will be an update form eventually but for now Im just trying to insert the image

 

if (isset($_POST['update_field'])) {
//
//	$intro = trim($_POST['intro']);
//	$intro = mysql_real_escape_string($intro);
//	$intro = mysql_query("UPDATE clubsstuff SET intro = '$intro' WHERE ID = '".$intro['cID']."' ") or die(mysql_error());	
//another photo uploader
$fileName = $_FILES['intro_image']['name'];
$tmpName = $_FILES['intro_image']['tmp_name'];
$fileSize = $_FILES['intro_image']['size'];
$fileType = $_FILES['intro_image']['type'];
$randName =$User['memberID'].md5(rand() * time());
$FileName = $randName;
$folder = "/members/images/{$intro['county']}/";
//if ($FileSize >250000){$msg=$msg."Your uploaded file size is more than 250KB so please reduce the file size and then upload. Visit the help page to know how to reduce the file size.<BR>";
//$file_upload="false";}	
//	
//	}
//	
//	if (!($FileType =="image/jpeg" OR $intro_image_type=="image/gif")){$msg=$msg."Your uploaded file must be of JPG or GIF. Other file types are not allowed<BR>";
//$file_upload="false";}
move_uploaded_file($tmpName , "$folder".$FileName.$fileType) or die(mysql_error());
//connect to database again
include('../../Connections/database.php'); 
$FileName;
$time = time();
$qInsert = "INSERT INTO `images` 
(`image_name`, `creationDate`, user,c ID, album_id, intro_image)
	VALUES                    
	('$FileName', '$time', '".$User['member_ID']."', '".$intro['cID']."', '1', 'yes')";
			$rInsert = mysql_query($qInsert) or die(mysql_error()); 


//Tells you if its all ok 
$url = "edit.php";        
header("Location: ".$url.""); 

 

and the form

 

  <form action="" method="POST" enctype="multipart/form-data" name="c_image">
<input type="file" name="intro_image" id="intro_image">

    <input type="submit" name="update-field" id="update-field" value="Update">

Link to comment
https://forums.phpfreaks.com/topic/240210-image-upload-puzzle/
Share on other sites

Ok thank you PFMaBiSmAd but I now have this error.  This is my first image uploader so I have no idea how to trouble shoot it.  ive pinched and wrote my own code.  The uploady part was from a tut so I cant see whats up with it

 

Warning: move_uploaded_file(/members/images/Lancashire/000000000354ca08848008b86f5057364ae0dc09b8.image/jpegimage/jpeg) [function.move-uploaded-file]: failed to open stream: No such file or directory in /home/sites/site.com/public_html/members/edit/edit.php on line 37

 

Warning: move_uploaded_file() [function.move-uploaded-file]: Unable to move '/tmp/phpTFdk4s' to '/members/images/Lancashire/000000000354ca08848008b86f5057364ae0dc09b8.image/jpegimage/jpeg' in /home/sites/site.com/public_html/members/edit/edit.php on line 37

 

 

line 37 is

 

 

 

move_uploaded_file($tmpName , "$folder".$FileName.$fileType) or die(mysql_error());

Link to comment
https://forums.phpfreaks.com/topic/240210-image-upload-puzzle/#findComment-1233858
Share on other sites

right I noticed it had the file type on it twice so I changed the move upload file code to

 

 

move_uploaded_file($tmpName , "$folder".$FileName) or die(mysql_error());

 

Im still getting the error that says the directory does not exist.  Which is not true.  The directory that it is referring to does exist on the server.

Link to comment
https://forums.phpfreaks.com/topic/240210-image-upload-puzzle/#findComment-1233866
Share on other sites

cool thanks again  but if I put $_SERVER["DOCUMENT_ROOT"] at the front of the string

$folder = "".$_SERVER["DOCUMENT_ROOT"]."members/images/{$intro['county']}/";

 

it error again but the path looks as follows...........

 

http://www.site.com/public_html/members/images/lancashire/000000000324587b2446acd77b5a31fca2e7fec2fc.image/jpeg

 

Obviously public shoud not be there

Link to comment
https://forums.phpfreaks.com/topic/240210-image-upload-puzzle/#findComment-1233879
Share on other sites

The link I posted stated that a leading / on a file system path refers to the root of the current hard disk. Do you know what the root of the current hard disk means?

 

If your $_SERVER["DOCUMENT_ROOT"] contains http://www, then who ever setup the virtual host configuration on your server didn't know what they should set it to.

Link to comment
https://forums.phpfreaks.com/topic/240210-image-upload-puzzle/#findComment-1233898
Share on other sites

yes I know what the root mean.  My site is hosted from Heart Internet.  A massive company in which My words would have no effect over.  If im in the folder

 

/members/edit

 

and my page is called edit.  Then surely to reference an image from the root it would be

 

/images

 

or even

../images

 

Other images and files on the site are used this way so why when I write

 

 

$folder = "/members/images/{$intro['county']}/";

 

does it say the path does not exist and why even if i type it not go from.

 

 

http://www.thesite.com/members/images/ (image name here)

does it still give me a server error like so..............

 

[Thu Jun 23 18:49:04 2011] [error] [client 94.5.254.197] PHP Warning:  move_uploaded_file() [<a href='function.move-uploaded-file'>function.move-uploaded-file</a>]: Unable to move '/tmp/phpWwYpSt' to 'http://www.site.com/members/images/Lancashire/0000000003d75b6a81a8c42da6028c835dd7cda019.image/jpeg' in /home/sites/site.com/public_html/members/edit/edit-club-intro.php on line 35, referer: http://www.site.com/members/edit/edit-club-intro.php

 

 

 

 

  Maybe I dont understand properly as im really confused now.  Can somebody at least explain the previous post or the error above?

 

Thank you

 

 

 

Link to comment
https://forums.phpfreaks.com/topic/240210-image-upload-puzzle/#findComment-1233936
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.