deansaddigh Posted May 18, 2010 Share Posted May 18, 2010 hi guys i want to set the image dimensions of an image before it gets uploaded, does anyone know how to do this. Here my uploader.php <?php include("includes/connection.php"); // Where the file is going to be placed $schoolimage = "SchoolImages/"; //This path will be stored in the database as it does not contain the filename $currentdir = getcwd(); $path = $currentdir . '/' . $schoolimage; // Get the schoolid for the image and school linker table $schoolid = $_POST['schoolid']; //Get the school name $query = "SELECT * FROM school WHERE school_id = ".$schoolid; $result = mysql_query($query) or die("Error getting school details"); $row = mysql_fetch_assoc($result); $schoolname = $row['name']; //Use this path to store the path of the file in the database. echo $filepath = $schoolimage . $schoolname; //Create the folder if it does not already exist if(!file_exists('SchoolImages')) { if(mkdir('SchoolImages')) { echo 'Folder ' . 'SchoolImages' . ' created.'; } else { echo 'Error creating folder ' . 'SchoolImages'; } } //Store the folder for the course title. if(!file_exists( $filepath )) { if(mkdir( $filepath )) { echo 'Folder ' . $schoolname . ' created.'; } else { echo 'Error creating folder ' . $schoolname; } } // Where the file is going to be placed $target_path = $filepath; // Add the original filename to our target path. Result is "uploads/filename.extension" $target_path = $target_path . '/' . basename( $_FILES['uploadedfile']['name']); if(move_uploaded_file($_FILES['uploadedfile']['tmp_name'], $target_path)) { echo "The file ". basename( $_FILES['uploadedfile']['name'])." has been uploaded"; $filename = $_FILES['uploadedfile']['name']; //Store the filename, path other criteria in the database $query = "INSERT INTO image(image_id, name, path) VALUES(0, '$filename', '$filepath')"; //Perform the query $add = mysql_query($query, $conn) or die("Unable to add the image details to the database"); $imageid = mysql_insert_id(); //Store the filename, path other criteria in the database $query = "INSERT INTO image_school( image_id, school_id ) VALUES('$imageid', '$schoolid')"; //Perform the query $add = mysql_query($query, $conn) or die("Unable to add the image details to the database"); $message = 'Upload Successful'; //Close the connection to the database mysql_close($conn); header("Location: add_school_photo_form.php? message=$message"); exit(); } else { $message = 'There was an error uploading the file, please try again!'; //Close the connection to the database mysql_close($conn); header("Location: add_school_photo_form.php? message=$message"); exit(); } ?> Link to comment https://forums.phpfreaks.com/topic/202135-specifying-image-dimesnions-when-uploading/ Share on other sites More sharing options...
scampbell Posted May 18, 2010 Share Posted May 18, 2010 Use getimagesize http://php.net/manual/en/function.getimagesize.php Link to comment https://forums.phpfreaks.com/topic/202135-specifying-image-dimesnions-when-uploading/#findComment-1059974 Share on other sites More sharing options...
litebearer Posted May 18, 2010 Share Posted May 18, 2010 I know its semantics, however, "BEFORE" indicates client-side. PHP is server-side and cannot get that info until AFTER the image is uploaded. You can use javascript to get it client-side. Everthing depends upon your objective. From your code are you looking to resize the image if it is too big? Link to comment https://forums.phpfreaks.com/topic/202135-specifying-image-dimesnions-when-uploading/#findComment-1059977 Share on other sites More sharing options...
scampbell Posted May 18, 2010 Share Posted May 18, 2010 You can use getimagesize on the temp file BEFORE moving it anywhere. If you want to use javascript I suggest asking in the javascript forum, not PHP. Link to comment https://forums.phpfreaks.com/topic/202135-specifying-image-dimesnions-when-uploading/#findComment-1059979 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.