PHP file upload HELP PLEASE ASAP


#1

Hi ,

Im having problems with images being auto deleted off the server but after a few hours not straight away ,

I have user profile pictures using the same upload script and these images dont get deleted at all, but the events images will auto delete a few hours after upload.

Im using move_uploaded_file to send the images to a folder called event_images and the file permissions are set to 777 , any help with this would be brillant thanks alot ian .


#2

I would contact your host about that. Few options, 1, someone else is doing it, 2, they’re being moved by a script to another folder or 3, the host is deleting them, 1 other, someone hates you and is trying to make you loose your marbles :slight_smile:


#3

Thanks for the reply , I thought it was someone messing about but the website is live now so I don’t think the site owner would do this … I did ask thou lol , ill have to contact the hosting company as it seems as there deleting them , could the server think that folderis the temp folder and deleting them ? That’s the only thing I can think of.


#4

Hmmm, sounds more like they get put in a tempdir then. Now I’m curious.


#5

I’ll explain in abit more detail then .

Basically I’ve developed a music based website and music acts can upload an image to be displayed as there profile photo , on there control panel they have the option to post an event , this includes text and an image , both user profile pictures and event images use move_uploaded_file , the photo goes to root/users/user_photos and events go to root/users/event_images , they folders are both set to file permission 777 . The user profile pictures are not being deletes by the event images are hours or days after first upload. This is my first dev project and have never come across this problem before . I know that images stored in the tmp dir are auto deleted after a certain time period but the folder event_images isnt a temp folder , again any help would be good

Thanks Ian


#6

No folder should have 777 for permissions unless you’re using cronjobs. couldn’t really tell you without seeing the upload code though.


#7

Oh ok i didnt know that , below is the upload code . This code is used on the events page also .

[php]

if(isset($file)){ //check if the file has been selected for upload and do th following checks.

 $image = addslashes(file_get_contents($_FILES['fileField'] ['tmp_name'])); // get the content of the image ready to be stored in an database.
 $image_name = addslashes($_FILES['fileField']['name']); // get the name of the image.
 $image_size = getimagesize($_FILES['fileField'] ['tmp_name']); // check the file is an image.
	 
 if($image_size == FALSE) { // this checks to see if the uplaoded file is an image or not.
	 $error .= " Please Only upload images"; // this displays if its not an image file.
}

}

// if there are no errors update the datebase
if(empty($error)){
// if there are no errors Insert the information into the database

      $new_name = mysql_insert_id(); // get the id of the new row and rename the image
	  $upload = move_uploaded_file($_FILES['fileField']['tmp_name'], '/home/bookthat/public_html/users/event_images/'.$new_name.'.jpg');

// if the insert is succesful
	if(!$sql){
		 $error .="Failed to enter the new event , please try again ";
	 }else{
	 	// show a message to confirm the event has been added
			$confirm .="Thank you, your event has been added.";
	 }
	
}

}// isset end
[/php]

Thanks Ian