arbitter Posted January 14, 2012 Share Posted January 14, 2012 Hi there. I'm making an album-upload-thingy. So far I've written the script that uploads an image, changes it's name, makes some directorys, makes a table, and inserts the image name in the table. Here's the script: <?php if(isset($_POST['addAlbum'])){ if(empty($_POST['naam']) || empty($_POST['urlnaam'])){ $_SESSION['melding'] = 'U hebt niet alle verplichte velden ingevuld!'; header('Location: ward/fotos'); exit(); } $naam = mysql_real_escape_string(htmlentities($_POST['naam'])); $urlnaam = mysql_real_escape_string(urlencode(str_replace(' ','',strtolower($_POST['urlnaam'])))); mysql_select_db('dyfemtaw_fotos'); $result = mysql_query("SELECT * FROM albums WHERE naam='$naam'")or die('result:' .mysql_error()); $result2 = mysql_query("SELECT * FROM albums WHERE urlnaam='$urlnaam'")or die('result2:'.mysql_error()); if(mysql_num_rows($result)==0 && mysql_num_rows($result2)==0){ mysql_select_db('dyfemtaw_fotos'); mysql_query("INSERT INTO albums (naam,urlnaam) VALUES ('$naam','$urlnaam')")or die('insert' .mysql_error()); mysql_query("CREATE TABLE $urlnaam( `id` INT NOT NULL AUTO_INCREMENT PRIMARY KEY , `photoid` BIGINT NOT NULL , `type` VARCHAR( 5 ) NOT NULL , `description` VARCHAR( 200 ) NOT NULL)")or die('create: '.mysql_error()); mkdir('fotos/'.$urlnaam); mkdir('fotos/'.$urlnaam.'/large'); mkdir('fotos/'.$urlnaam.'/thumbs'); //getting the extension of the file $filename = strtolower($_FILES['bestand']['name']); $exts = explode(".", $filename); $n = count($exts)-1; $exts = '.' . $exts[$n]; $newname = rand(111111,999999) . time(); $targetpath = 'fotos/' . $urlnaam . '/' . $newname . $exts; mysql_query("INSERT INTO $urlnaam (photoid,type) VALUES ('$newname','$exts')")or die(mysql_error()); if(move_uploaded_file($_FILES['bestand']['tmp_name'], $targetpath)) { $_SESSION['melding'] = 'Het bestand ' . basename( $_FILES['bestand']['name']). " is geüpload."; header('Location: ward/fotos'); exit(); }else{ $_SESSION['melding'] = "Er is een probleem opgetreden."; header('Loaction: ward/fotos'); exit(); } }else{ $_SESSION['melding'] = 'Deze naam is al gekozen.'; header('Location: ward/fotos'); exit(); } } ?> So what it does: Check if the name of the database exists (name of the database is user inputted) if not -> insert in the 'albums' table that album and it's name. From the urlname, make a new table make directorys for the large (600px) files and the thumbnail (120px) files get the extension of the file make name of file with a random number and time() insert the file name and the extension in the newly made table with the urlname of the album move the file So what I still need to do is resize the image twice; the large one (600px) should be stored in the album/large directory, the small one should be stored in the album/thumbs directory. And then, I need to find a way to implement this to Uploadify, so I can allow multi-uploads Also, I'm not quite sure my script is safe; I mean, it can make the database and still fail to upload the image, which ofcourse isn't good is it... Quote Link to comment https://forums.phpfreaks.com/topic/255006-upload-script-with-resize-uploadify/ Share on other sites More sharing options...
litebearer Posted January 14, 2012 Share Posted January 14, 2012 Here is what I use for resizing... http://www.nstoia.com/sat/resize/ Quote Link to comment https://forums.phpfreaks.com/topic/255006-upload-script-with-resize-uploadify/#findComment-1307566 Share on other sites More sharing options...
arbitter Posted January 14, 2012 Author Share Posted January 14, 2012 The script seems to work good, but something rather weird is happening. This does work: Resize_Image($fullname,$fullname,600,600,'fotos/'.$urlnaam.'/large/','fotos/'.$urlnaam.'/large/'); but this does not work: Resize_Image($fullname,$fullname,120,120,'fotos/'.$urlnaam.'/large/','fotos/'.$urlnaam.'/thumbs/'); even though the thumbs folder does exist... Quote Link to comment https://forums.phpfreaks.com/topic/255006-upload-script-with-resize-uploadify/#findComment-1307572 Share on other sites More sharing options...
arbitter Posted January 14, 2012 Author Share Posted January 14, 2012 And another problem is: when you insert ' and " in the names ($_POST['naam'] and $_POST['urlnaam']), the values do get inserted into the 'albums' table, but there is no table made... Is there a function that strips things so they can be a table name? So I need something that cleans ANYTHING to something that can safely be used in a link and as a table name... Quote Link to comment https://forums.phpfreaks.com/topic/255006-upload-script-with-resize-uploadify/#findComment-1307573 Share on other sites More sharing options...
litebearer Posted January 14, 2012 Share Posted January 14, 2012 you reversed the order.. should be Resize_Image($fullname,$fullname,120,120,NEW_IMAGE__HERE, ORIGINAL_IMAGE_HERE); Quote Link to comment https://forums.phpfreaks.com/topic/255006-upload-script-with-resize-uploadify/#findComment-1307576 Share on other sites More sharing options...
arbitter Posted January 14, 2012 Author Share Posted January 14, 2012 Darnit My bad, works like a charm now! Any idea on the uploadify-part? Quote Link to comment https://forums.phpfreaks.com/topic/255006-upload-script-with-resize-uploadify/#findComment-1307577 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.