June 24th, 2017, 05:57 AM | #11 | ||
in memoriam Max
Join Date: Jun 2009
Location: Germany
Posts: 3,586
Thanks: 122,092
Thanked 47,469 Times in 3,337 Posts
|
Quote:
Quote:
__________________
Genius may have its limitations, but stupidity is not thus handicapped. |
||
June 24th, 2017, 03:17 PM | #12 | |
Vintage Member
Join Date: Apr 2011
Location: Tulsa
Posts: 23,168
Thanks: 612
Thanked 275,343 Times in 23,048 Posts
|
Quote:
Also, I don't like the fact that they could increase the size of the gallery hash from 5 - whatever number of characters. It means I have to modify my code to accommodate later because they didn't just use a larger number now.
__________________
My posts are scripted, sorry if the preview images aren't great, but the whole gallery is in the link
To view links or images in signatures your post count must be 0 or greater. You currently have 0 posts. If I post any duplicates, please PM me and I will remove them |
|
June 24th, 2017, 03:48 PM | #13 | ||
in memoriam Max
Join Date: Jun 2009
Location: Germany
Posts: 3,586
Thanks: 122,092
Thanked 47,469 Times in 3,337 Posts
|
Quote:
Code:
<input type="file" name="img[]" accept="image/gif,image/png,image/jpeg" multiple> Quote:
__________________
Genius may have its limitations, but stupidity is not thus handicapped. Last edited by retroanalyst; June 26th, 2017 at 03:34 PM.. Reason: fix quote |
||
June 24th, 2017, 07:32 PM | #14 | |
Vintage Member
Join Date: Apr 2011
Location: Tulsa
Posts: 23,168
Thanks: 612
Thanked 275,343 Times in 23,048 Posts
|
Quote:
This gets into protecting your inputs, and data validation. If you were to have a field of only numbers you would limit it to only integer inputs so no one could accidentally put letters there. I do IT for a living....
__________________
My posts are scripted, sorry if the preview images aren't great, but the whole gallery is in the link
To view links or images in signatures your post count must be 0 or greater. You currently have 0 posts. If I post any duplicates, please PM me and I will remove them |
|
The Following 3 Users Say Thank You to herkalurk For This Useful Post: |
June 26th, 2017, 03:46 PM | #15 | |
in memoriam Max
Join Date: Jun 2009
Location: Germany
Posts: 3,586
Thanks: 122,092
Thanked 47,469 Times in 3,337 Posts
|
Quote:
While I was looking closer at the API, I wondered why there are two different hashes in the first place and why they don't use a single long hash. Must be because they want to allow sharing galleries via Twitter, so the URL had better be short.
__________________
Genius may have its limitations, but stupidity is not thus handicapped. |
|
June 26th, 2017, 04:01 PM | #16 | |
Vintage Member
Join Date: Apr 2011
Location: Tulsa
Posts: 23,168
Thanks: 612
Thanked 275,343 Times in 23,048 Posts
|
Quote:
__________________
My posts are scripted, sorry if the preview images aren't great, but the whole gallery is in the link
To view links or images in signatures your post count must be 0 or greater. You currently have 0 posts. If I post any duplicates, please PM me and I will remove them |
|
June 26th, 2017, 04:09 PM | #17 |
in memoriam Max
Join Date: Jun 2009
Location: Germany
Posts: 3,586
Thanks: 122,092
Thanked 47,469 Times in 3,337 Posts
|
Gallery upload script
I was unhappy with the lack of gallery support in existing pixhost upload tools, so I decided to sit down and write my own little shell script. All it currently does is take a folder name as argument (and a gallery name, optionally) and upload all images in that folder to a gallery on pixhost. At the end, it prints the gallery URL which you had better save lest you never find your uploaded pictures.
Not really sophisticated, but it's less than 50 lines of code. Professionals like herkalurk might scoff at it, but for us laymen it's a start. Code:
#!/bin/sh # Script to upload all images in a directory to pixhost, # creating a gallery there. # Parameters: directory containing the files to upload (mandatory), # gallery name (recommended but optional, use directory name by default) set -e set -u DIR=$1 [ -n "$DIR" ] || { echo "$0: Need a directory argument" >&2; exit 1; } [ -d "$DIR" ] || { echo "$0: $1 is not a directory" >&2; exit 1; } GALLERY_NAME=${2:-$(basename "${DIR}")} # Initialize gallery and extract returned values PARAMS=$(curl -s -S -X POST --include "https://api.pixhost.to/galleries" \ -H 'Content-Type: application/x-www-form-urlencoded; charset=utf-8' \ -H 'Accept: application/json' \ -d "gallery_name=${GALLERY_NAME}" | tail -n1 | tr -d '"') HASH=$(echo $PARAMS | sed 's/.*gallery_hash://' | sed 's/[,}].*//') URL=$(echo $PARAMS | sed 's/.*gallery_url://' | sed 's/[,}].*//') UPLOAD_HASH=$(echo $PARAMS | sed 's/.*gallery_upload_hash://' | sed 's/[,}].*//') # Upload images, silently skipping apparent non-image files for now. for file in "${DIR}"/* ; do case ${file} in *jpg|*.JPG|*.jpeg|*.gif|*.png) curl -s -S -X POST --include "https://api.pixhost.to/images" \ -H 'Content-Type: multipart/form-data; charset=utf-8' \ -H 'Accept: application/json' \ -F "img=@${file}" \ -F 'content_type=1' \ -F 'max_th_size=180' \ -F "gallery_hash=$HASH" \ -F "gallery_upload_hash=$UPLOAD_HASH" > /dev/null ;; esac done # Finalize gallery curl -s -S -X POST --include "https://api.pixhost.to/galleries/$HASH/finalize" \ -H 'Content-Type: application/x-www-form-urlencoded; charset=utf-8' \ -H 'Accept: application/json' \ -d "gallery_upload_hash=$UPLOAD_HASH" > /dev/null echo "Gallery \"$GALLERY_NAME\" available at $URL." |
The Following 4 Users Say Thank You to retroanalyst For This Useful Post: |
October 29th, 2017, 05:43 AM | #18 |
Vintage Member
Join Date: Apr 2011
Location: Tulsa
Posts: 23,168
Thanks: 612
Thanked 275,343 Times in 23,048 Posts
|
I actually wrote the gallery upload in php. I save the information to a mysql database so I know all of my galleries for later user. I tend to upload many at a time, so this makes it easier to recall later. This requires the unirest extra code as displayed in the tutorial at pixhosts's api.
The script works by passing 2 arguments: first is the name of the gallery you're creating, second is the folder where the images are located. Code:
<?php require_once '/home/user/unirest-php/src/Unirest.php'; $db=mysqli_connect('localhost','pix','pix','pix'); function create_gal($gal_name) { $response = Unirest\Request::post("https://api.pixhost.to/galleries", [ "Content-Type" => "application/x-www-form-urlencoded; charset=utf-8", "Accept" => "application/json" ], Unirest\Request\Body::form([ "gallery_name" => $gal_name ]) ); print_r($response); return $response; } function finalize() { global $gal_json; $response = Unirest\Request::post("https://api.pixhost.to/galleries/{$gal_json->body->gallery_hash}/finalize", [ "Content-Type" => "application/x-www-form-urlencoded; charset=utf-8", "Accept" => "application/json" ], Unirest\Request\Body::form([ "gallery_upload_hash" => "{$gal_json->body->gallery_upload_hash}" ]) ); } function upload($img) { global $gal_json; $response = Unirest\Request::post("https://api.pixhost.to/images", [ "Content-Type" => "multipart/form-data; charset=utf-8", "Accept" => "application/json" ], [ "img" => Unirest\Request\Body::file($img), "content_type" => "1", "max_th_size" => "180", "gallery_hash" => $gal_json->body->gallery_hash, "gallery_upload_hash" => $gal_json->body->gallery_upload_hash ] ); print_r($response); return $response; } //$gal_json=json_decode(create_gal($argv[1])); $gal_json=create_gal($argv[1]); mysqli_query($db,"insert into galleries (`gallery_name`,`gallery_hash`,`gallery_upload_hash`,`gallery_url`) values ('{$gal_json->body->gallery_name}','{$gal_json->body->gallery_hash}','{$gal_json->body->gallery_upload_hash}','{$gal_json->body->gallery_url}');"); foreach(scandir($argv[2]) as $entry) { if ($entry != "." && $entry != ".." && $entry != "upload_folder.php") { $img_json=upload("{$argv[2]}{$entry}"); mysqli_query($db,"insert into images (`gallery_hash`,`name`,`show_url`,`th_url`) values ('{$gal_json->body->gallery_hash}','{$img_json->body->name}','{$img_json->body->show_url}','{$img_json->body->th_url}');"); } } finalize(); mysqli_close($db); ?> Code:
-- phpMyAdmin SQL Dump -- version 4.4.15.10 -- https://www.phpmyadmin.net -- -- Host: localhost -- Generation Time: Oct 29, 2017 at 01:43 AM -- Server version: 5.5.56-MariaDB -- PHP Version: 5.4.16 SET SQL_MODE = "NO_AUTO_VALUE_ON_ZERO"; SET time_zone = "+00:00"; /*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */; /*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */; /*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */; /*!40101 SET NAMES utf8mb4 */; -- -- Database: `pix` -- -- -------------------------------------------------------- -- -- Table structure for table `galleries` -- CREATE TABLE IF NOT EXISTS `galleries` ( `ID` int(8) NOT NULL, `gallery_name` varchar(100) NOT NULL, `gallery_hash` varchar(5) NOT NULL, `gallery_upload_hash` varchar(40) NOT NULL, `gallery_url` varchar(60) NOT NULL, `addTime` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ) ENGINE=MyISAM DEFAULT CHARSET=utf8; -- -------------------------------------------------------- -- -- Table structure for table `images` -- CREATE TABLE IF NOT EXISTS `images` ( `ID` int(8) NOT NULL, `gallery_hash` varchar(5) NOT NULL, `name` varchar(150) NOT NULL, `show_url` varchar(150) NOT NULL, `th_url` varchar(150) NOT NULL, `addTime` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ) ENGINE=MyISAM DEFAULT CHARSET=utf8; -- -- Indexes for dumped tables -- -- -- Indexes for table `galleries` -- ALTER TABLE `galleries` ADD PRIMARY KEY (`ID`) USING BTREE, ADD UNIQUE KEY `gallery_hash` (`gallery_hash`) USING BTREE, ADD KEY `addTime` (`addTime`); -- -- Indexes for table `images` -- ALTER TABLE `images` ADD PRIMARY KEY (`ID`), ADD KEY `gallery_hash` (`gallery_hash`), ADD KEY `addTime` (`addTime`); -- -- AUTO_INCREMENT for dumped tables -- -- -- AUTO_INCREMENT for table `galleries` -- ALTER TABLE `galleries` MODIFY `ID` int(8) NOT NULL AUTO_INCREMENT; -- -- AUTO_INCREMENT for table `images` -- ALTER TABLE `images` MODIFY `ID` int(8) NOT NULL AUTO_INCREMENT; /*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */; /*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */; /*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */;
__________________
My posts are scripted, sorry if the preview images aren't great, but the whole gallery is in the link
To view links or images in signatures your post count must be 0 or greater. You currently have 0 posts. If I post any duplicates, please PM me and I will remove them |
|
|