Today's Posts Follow Us On Twitter! TFL Members on Twitter  
Forum search: Advanced Search  
Navigation
Marketplace
  Members Login:
Lost password?
  Forum Statistics:
Forum Members: 24,254
Total Threads: 80,792
Total Posts: 566,471
There are 1066 users currently browsing (tf).
 
  Our Partners:
 
  TalkFreelance     Design and Development     Programming     PHP and MySQL :

image uploading, need help

Thread title: image uploading, need help
Reply    
    Thread tools Search this thread Display Modes  
11-05-2011, 10:26 PM
#1
creativejen is offline creativejen
Status: Paladin
Join date: Jul 2006
Location: Sheffield, UK
Expertise: design, front-end markup
Software: Photoshop
 
Posts: 2,353
iTrader: 25 / 96%
 

creativejen is an unknown quantity at this point

Send a message via MSN to creativejen

  Old  image uploading, need help

Hey guys,

I wrote this pretty quickly; http://screensnapr.com/v/Q2SqQJ.png

If the file doesnt exist, then it uploads and saves the image fine. But, if the file does already exist, then i add an 8 digit number to the beginning of the file. It gives the url fine, but the problem is, it doesnt save the image.

Any ideas guys?

Reply With Quote
11-06-2011, 12:44 PM
#2
thatjamie is offline thatjamie
thatjamie's Avatar
Status: Ruby on Rails Developer
Join date: Oct 2004
Location: England, UK
Expertise: Ruby, Rails, jQuery
Software: Chocolat, Sublime Text 3
 
Posts: 2,343
iTrader: 14 / 94%
 

thatjamie is on a distinguished road

Send a message via Skype™ to thatjamie

  Old

Firstly, I'd create random generated names for the images so you don't need to do a check if it exists, work on it time so the number can only go forward, saves the if/else malarky.

Post removed, updating code. Brb.

Reply With Quote
11-06-2011, 03:58 PM
#3
creativejen is offline creativejen
Status: Paladin
Join date: Jul 2006
Location: Sheffield, UK
Expertise: design, front-end markup
Software: Photoshop
 
Posts: 2,353
iTrader: 25 / 96%
 

creativejen is an unknown quantity at this point

Send a message via MSN to creativejen

  Old

I come up with a solution, just dont even check if it exists...

PHP Code:
$random_digit=rand(00000000,99999999);

move_uploaded_file($_FILES["file"]["tmp_name"],
"images/" $random_digit $_FILES["file"]["name"]);
$newthumb "images/" $random_digit $_FILES["file"]["name"]; 

Reply With Quote
11-07-2011, 02:09 PM
#4
ThePro is offline ThePro
Status: I'm new around here
Join date: Nov 2011
Location: Denmark
Expertise: Web Back End / Front End
Software: Photoshop, Netbeans, xampp
 
Posts: 1
iTrader: 0 / 0%
 

ThePro is on a distinguished road

  Old

yeah that would work

Reply With Quote
11-07-2011, 06:01 PM
#5
Village Genius is offline Village Genius
Village Genius's Avatar
Status: Geek
Join date: Apr 2006
Location: Denver, CO
Expertise: Software
Software: Chrome, Notepad++
 
Posts: 6,894
iTrader: 18 / 100%
 

Village Genius will become famous soon enough

  Old

While the chances of a duplicate are slim the only completely sure way to do it is to use a do...while loop and rename it every time an existing one is made, to give a quickly typed pseudocode example

PHP Code:
$uploaded=false;
do{
$randNum=rand(0,99999);
if 
file+$randnum does not exist
upload file
$uploaded
=true;
end if
} while(
$uploaded==false); 

11-10-2011, 02:35 AM
#6
Mauro.Casas is offline Mauro.Casas
Mauro.Casas's Avatar
Status: Member
Join date: Jun 2008
Location: Buenos Aires, Argentina
Expertise: programming, wizardy
Software:
 
Posts: 165
iTrader: 8 / 100%
 

Mauro.Casas is on a distinguished road

Send a message via Skype™ to Mauro.Casas

  Old

That random digit think should do the work, but as they said, I'd try to slim down the chances by adding at least one or two characters at the end or beggining of the name, it's better to avoid than to regret.

Cheers!

Reply With Quote
Reply    


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

  Posting Rules  
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump:
 
  Contains New Posts Forum Contains New Posts   Contains No New Posts Forum Contains No New Posts   A Closed Forum Forum is Closed