lpxxfaintxx Posted March 19, 2006 Share Posted March 19, 2006 [code] <?phpob_start();include 'db.php'; $description = $_POST['description']; $description = $_POST['category']; $username = $userdata['user_name']; $filename = str_replace(' ', '', $_FILES['userfile']['name']); $tblw = strlen($filename); $ext = substr($filename, $tblw-3, $tblw); $exts = array("png", "gif", "jpg");if ($ext == 'png' OR $ext == 'gif' OR $ext == 'jpg') { $idq = mysql_query("SELECT `id` FROM `files` ORDER BY `id` DESC LIMIT 1"); $ida = mysql_fetch_assoc($idq); $id = $ida['id'] + 1; im $uploaddir = '/wamp/www/aimphotogallery/upload/$owner'; $path = '/wamp/www/aimphotogallery/upload/$owner'.$id. '.'.$ext; $uploadfile = $uploaddir . $id . "." . $ext; $idpath = 'http://localhost/aimphotogallery/upload/'.$id. '.'.$ext;move_uploaded_file($_FILES['userfile']['tmp_name'], $uploadfile);mysql_query("INSERT INTO `memberuploads` (`id`,`path`,`owner`,`idpath`,`description`) VALUES('$id','$path','$username','$idpath','$description')");mysql_query("INSERT INTO `files` (`id`,`path`,`owner`,`idpath`,`description`) VALUES('$id','$path','$username','$idpath','$description')");header("Location: http://localhost/aimphotogallery/viewimage.php?id=$id");};ob_end_flush();?>[/code]1) I am trying to make an error message when something has gone wrong while uploading. The line [code]if ($ext == 'png' OR $ext == 'gif' OR $ext == 'jpg') {[/code] makes it harder to do. I'm really confused on how I should do it.2) This is my general upload script. How would I integrate Javascript so that users can upload multiple files? The oddness of how this script works makes everything a bit harder :(3) [code] $uploaddir = '/wamp/www/aimphotogallery/upload/$owner';[/code] If the directory doesn't exists, how can I create the directory within this script?Links, suggestions, answers welcome!Regards, LPXXFAINTXX Quote Link to comment Share on other sites More sharing options...
shortj75 Posted March 19, 2006 Share Posted March 19, 2006 you may have to do something like this[code]if ($ext == 'png' OR $ext == 'gif' OR $ext == 'jpg') {your upload code here}else{echo "Sorry you are trying to upload an unsupported format";}[/code]and for the upload directory to create a new dir[code]mkdir("path/to/new/dir/$owner") or die("Sorry I could not make the directory you requested<BR>");[/code][example: mkdir("c:/inetpub/wwwroot/$owner") ] Quote Link to comment Share on other sites More sharing options...
lpxxfaintxx Posted March 22, 2006 Author Share Posted March 22, 2006 [!--quoteo(post=356342:date=Mar 19 2006, 12:44 AM:name=shortj75)--][div class=\'quotetop\']QUOTE(shortj75 @ Mar 19 2006, 12:44 AM) [snapback]356342[/snapback][/div][div class=\'quotemain\'][!--quotec--]mkdir("path/to/new/dir/$owner") or die("Sorry I could not make the directory you requested<BR>");[/code][example: mkdir("c:/inetpub/wwwroot/$owner") ][/quote]What if the directory exists? Would the script run properly? Quote Link to comment Share on other sites More sharing options...
wickning1 Posted March 22, 2006 Share Posted March 22, 2006 I cleaned it up a bit, maybe you can glean some useful info from my code.[code]<?phpob_start();include 'db.php';if (!isset($_FILES['userfile'])) throw_exception("You didn't upload a file.");// which of these is correct? they can't both be$description = $_POST['description'];$description = $_POST['category'];$username = $userdata['user_name'];$filename = str_replace(' ', '', $_FILES['userfile']['name']);$tblw = strlen($filename);$ext = substr($filename, $tblw-3, $tblw);$exts = array("png", "gif", "jpg");if (!in_array($ext, $exts)) throw_exception("Unsupported file extension.");$idq = mysql_query("SELECT MAX(id) FROM files") or throw_exception(mysql_error());$ida = mysql_fetch_assoc($idq);$id = $ida['id'] + 1;$dir = '/wamp/www/aimphotogallery/upload';if (!file_exists($dir)) mkdir($dir, 0777) or throw_exception("Could not create upload directory");$path = $dir . '/'.$owner.$id.'.'.$ext;$idpath = 'http://localhost/aimphotogallery/upload/'.$id. '.'.$ext;move_uploaded_file($_FILES['userfile']['tmp_name'], $path) or throw_exception("Could not complete upload.");mysql_query("INSERT INTO `memberuploads` (`id`,`path`,`owner`,`idpath`,`description`) VALUES('$id','$path','$username','$idpath','$description')") or throw_exception(mysql_error());mysql_query("INSERT INTO `files` (`id`,`path`,`owner`,`idpath`,`description`) VALUES ('$id','$path','$username','$idpath','$description')") or throw_exception(mysql_error());header("Location: http://localhost/aimphotogallery/viewimage.php?id=$id");function throw_exception($msg) { echo $msg; exit;}?>[/code] 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.