jordz Posted March 6, 2010 Share Posted March 6, 2010 Hey All, Okay I have a photo uploader script that basically uploads a photo to the server and renames it. The name is processed by somethings: //Calculate next ID number. $query = 'SELECT * from photos order by photo_id desc limit 1'; $calcid = mysql_fetch_array(mysql_query($query)); $id = $calcid['photo_id'] + 1; Right Im expecting the photo uploader to be used a lot at any one time so I' if I used this kind of script bad things will start to happen? I need some help in calculating a name, I thought about using random ID? If I use Random ID's at any point could one be the same? Is there a better way I could do this (well yeah obviously). Many thanks Jordan Quote Link to comment Share on other sites More sharing options...
PFMaBiSmAd Posted March 6, 2010 Share Posted March 6, 2010 If you want the actual file name to use an unique ID from a database table, use an auto_increment field in the table. INSERT the row in the table and use mysql_insert_id() to get the ID that was just assigned. If the whole filename consists of more than just the ID, insert empty data for the actual filename and go back and execute an UPDATE query to fill in the actual information once it has been assigned. Quote Link to comment Share on other sites More sharing options...
jordz Posted March 6, 2010 Author Share Posted March 6, 2010 Well basically what goes on is, You upload a file, select the file -> upload -> script uploads it to the server after it assigns the file you uploaded a new name which should be unique. Once that's processed it inserts to a database the ID (which also doubles as the file name, (it doesnt have to though) and then the file is viewed on the site. Jordan Quote Link to comment Share on other sites More sharing options...
PFMaBiSmAd Posted March 6, 2010 Share Posted March 6, 2010 So, the answer is YES and you would need to do what someone already suggested. Quote Link to comment Share on other sites More sharing options...
jordz Posted March 7, 2010 Author Share Posted March 7, 2010 I haven't actually been able to try test out the theory properly but thinking about it, for the way in which you describe it you'd need to run the insert query first then process the file then go back and update the table? If this is the case then if something goes wrong half way through executing the script then I'd be left with unnecessary rows from error'd uploads? Well at least there could be a chance right? Quote Link to comment Share on other sites More sharing options...
jordz Posted March 7, 2010 Author Share Posted March 7, 2010 I also believe this is in the wrong section? Maybe my mistake? Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.