Jump to content

han003

Members
  • Posts

    10
  • Joined

  • Last visited

han003's Achievements

Newbie

Newbie (1/5)

0

Reputation

  1. Hi! Lets say I make a site where users can register, and instead of having the profile pages like www.mysite.com/user.php?user=randomguy1 I want to make them like www.mysite.com/randomguy1 Hope you understand!
  2. If I dont do the size check I and a photo is larger than 1mb the whole thing gets fucked up, thats why its there ?
  3. Hi I'm trying to upload multiple images to my database Problems I'm encountering: 1. Wont upload more than 20, if i select 32 then only 20 uploaded and the rest is not 2. If upload take too long I get a 403 forbidden 3. Seems to crash when photo size is more than 1mb, my webhost says the file size limit is 128mb so I don't know My HTML <form enctype="multipart/form-data" method="post" action="upload.php"> <table> <tr> <td class="left"><span>Album Name</span></td><td><input id="albumName" name="name" type="text" autocomplete="off" maxlength="40" /><br /></td> </tr> <tr> <td class="left"><span>Description</span></td><td><textarea name="description" cols="18" rows="2"></textarea></td> </tr> <tr> <td class="left"><span>Choose File(s)</span></td><td><input type="file" name="files[]" multiple="multiple" /></td> </tr> <tr> <td></td><td><input name="submit" type="submit" value="Upload"></td> </tr> </table> </form> My PHP <?php // INCLUDE RESIZE CLASS include("resize-class.php"); // CHECK IF FIELDS ISSET if (isset($_POST['submit']) && isset($_POST['name']) && isset($_POST['description'])) { $name = ($_POST['name']); $description = ($_POST['description']); // CREATE NEW ALBUM IF FIELDS ARE NOT EMPTY if (empty($name) || empty($description) || empty($_FILES['files'])) { echo 'Fill out all fields'; }else{ if(!isset($_FILES['files'])){ echo 'Please select a minimum of one file to upload'; }else{ $album_id = createTable($name, $description); addImages($album_id); } } } function addImages($album_id){ $count = count($_FILES['files']['name']); for($i = 0; $i < $count; $i++){ $file_name = $_FILES['files']['name'][$i]; $tmp = $_FILES['files']['tmp_name'][$i]; $extension = pathinfo($file_name, PATHINFO_EXTENSION); $size = $_FILES['files']['size'][$i]; if($extension == 'jpg' || $extension == 'jpeg' || $extension == 'png' || $extension == 'gif'){ if($size < 1000000){ uploadImages($tmp, $file_name, $extension, $album_id); }else{ } }else{ } } } function createTable($name, $description){ // CONNECT include '../includes/database.php'; // GET DATE $date = date('Y-m-d H:i:s'); // QUERY TO CREATE NEW ALBUM $query = "INSERT INTO albums (id, album_name, date_created, last_updated, thumb_id, album_description) VALUES (NULL, '$name', '$date', '$date', '1', '$description')"; // RUN QUERY mysql_query($query) or die("Error in query: " . mysql_error()); // GET TABLE ID $query = "SELECT id FROM `albums` ORDER BY id DESC LIMIT 1"; $result = mysql_query($query) or die("Error in query: " . mysql_error()); while($row = mysql_fetch_assoc($result)){ $album_id = $row['id']; } mysql_close(); return $album_id; } function uploadImages($tmp, $file_name, $extension, $album_id){ // CONNECT include '../includes/database.php'; $directory = '../images/'; // GET IMAGE DIMENSIONS list($width, $height, $type, $attr) = getimagesize($tmp); // GET MAIN IMAGE DATA $img_data = addslashes(file_get_contents($tmp)); move_uploaded_file($tmp, $directory . $file_name); // *** 1) Initialise / load image $resizeObj = new resize($directory . $file_name); // *** 2) Resize image (options: exact, portrait, landscape, auto, crop) $resizeObj -> resizeImage(240, 135, 'exact'); // *** 3) Save image $resizeObj -> saveImage($directory . $file_name, 100); // GET THUMB DATA $thumb_data = addslashes(file_get_contents($directory . $file_name)); ## ----------------------------------------------------------------- $query = "INSERT INTO photos (id, album_id, photo, thumb, photo_name, photo_description, filetype, height, width) VALUES (NULL, $album_id ,'$img_data', '$thumb_data', '$file_name', 'Description', '$extension', '$height', '$width')"; mysql_query($query) or die("Error in query: " . mysql_error()); unlink($directory . $file_name); // GET PHOTO ID $query = "SELECT id FROM photos WHERE album_id=$album_id ORDER BY id ASC LIMIT 1"; $result = mysql_query($query) or die("Error in query: " . mysql_error()); while($row = mysql_fetch_assoc($result)){ $thumb_id = $row['id']; } $query = "UPDATE albums SET thumb_id =$thumb_id WHERE id=$album_id"; mysql_query($query) or die("Error in query: " . mysql_error()); mysql_close(); } ?>
  4. When I try to save the image in my browser I only get img.php (which is the name of the file of the code posted below) how can I make it so its downloadable and set a custom filename? <?php header("Content-type: image/png"); include 'database.php'; $id = $_GET['id']; $query = "SELECT photo FROM photos WHERE id='$id';"; $result = mysql_query($query) or die("Invalid query: " . mysql_error()); $row = mysql_fetch_array($result); $image = imagecreatefromstring($row['thumb']); imagepng($image); imagedestroy($image); ?>
  5. han003

    Timeout

    Forbidden You don't have permission to access /upload.php on this server. Additionally, a 404 Not Found error was encountered while trying to use an ErrorDocument to handle the request. ------------------------------------- Thats what happens if it isnt finished uploading within 10 secs of pressing the submit button in my form and no cant have them in FTP, need database and need timeout to be gone or increased or anythiong!!
  6. han003

    Timeout

    Hi! Im currently inserting multiple images by running a for loop and then inserting them into my database. Problems I have is If the inserting takes more than 10secs If I try to insert more than 20 images at once, if I select 23 for insertion only 20 is inserted. I dont think I can access the ini file since my database is at a webhost.
  7. THere's my code I get an image from a folder but some of them are big, like over 1mb, so id like to make just thumbnails and show the thumbnails in the <img> tag, but if you're not willing to help then by all mean put this in the other forum thank you <?php $counter = 0; echo '<table><tr>'; foreach(glob("../Pics/Wallpapers/*.*") as $filename){ if ( $counter%5 == 0){ echo '</tr><tr><td>'; } else{ echo '<td>'; } echo '<div id="thumbs"><div id="image">'; echo '<a href="'. $filename .'"><img src="'. $filename .'" height="180" width="320" /></a></div>'; echo '<div id="text"><span>'. filesize($filename) .'</span></div></div>'; echo '</td>'; $counter++; } ?>
  8. Hi! After I've gotten an image from my database I'd like to make it small like a thumbnail, say 200x100, instead of 1920x1080. And after I've resized it I'd like to put it inside an <img>, this is like a gallery, with several rows of pictures. Any who can help? Thanks!
  9. Hi! I've made a simple registration form, and I'm currently using javascript to validate it. The thing is, I want to be able to check if username is available before they hit the submit button, and I don't know how to integrate PHP into form validation and stuff..
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.