Re: Save image name by user id

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hello,


yes I need to  know how to upload the files without overwriting
existing ones, and in my case want add member id just before the
original file name.

like if a member has a id 10 so file name should be like
"10_filename.jpg" in uploaded folder as well as in database.

Thanks,
Avi


--- In php-objects@xxxxxxxxxxxxxxx, "Joe Forsythe" <jforsythe@...> wrote:
>
> I'm not exactly clear on what you're asking here. It sounds like you
need
> to know how to upload the files without overwriting existing ones.
Is that
> correct? If so, the function you're looking for is file_exists()
combined
> with a bit of recursion. Something like this should get you there:
> $file_name = 'Your_file_name';
> $file_ext = '.jpg';
> $full_file_name = $file_name.$file_ext;
> $foo = 1;
> while (file_exists($full_file_name)) {
>    $full_file_name = $file_name.$foo.$file_ext;
>    $foo++;
> }
> 
> --
> Joe
> 
> > Hello,
> >
> > I need help to upload image with member id, like "m_id_filename.jpg"
> > just not to overwrite file.
> >
> > This is the path, and  i m sending m_id on image upload page..on this
> > page i am uploading 12 images, and i want to save every image with
> > m_id number, Ex:m_id_imagename.jpg
> >
> > http://localhost/sexyjobsmp/upload_photos.php?m_id=12
> >
> > folder name is "uploads" on which i m uploading images.
> >
> > here is the code for single image upload...
> >
> >
> >
> > if (is_uploaded_file ($_FILES['image_1']['tmp_name'])) {
> > 		if (move_uploaded_file($_FILES['image_1']['tmp_name'],
> > "uploads/{$_FILES['image_1']['name']}")) { // Move the file over.
> >
> > 			echo '<p>The file has been uploaded!</p>';
> >
> > 		} else { // Couldn't move the file over.
> > 			echo '<p><font color="red">The before image could not be
> > moved.</font></p>';
> > 			$image_1 = '';
> > 		}
> > 		$image_1 = $_FILES['image_1']['name'];
> > 	} else {
> > 		$image_1 = '';
> > 	}
> >
> > Please help me wth it...if possible modify the same code so it will be
> > easy for me.
> >
> > Thank you so much!
> > Avi
> >
> >
>



[Index of Archives]     [PHP Home]     [PHP Users]     [PHP Soap]     [Kernel Newbies]     [Yosemite]     [Yosemite Campsites]

  Powered by Linux