edit: To sum it all up, I wanted to see how to make a website generate a link after a file has been uploaded.
First time posting here, I hope I'm not breaking the rules by asking this, haha.
I'm trying to set up an upload function on my website by following the tutorial on tizag, but I can't seem to figure out how to make it that after uploading, the user is presented with a link to the file (like how you would upload something to imgur and receive a short link like this imgur.com/k4FzF6W ).
Thank you for your help! I'm very new to php and I'm not the best at code in general.
This all depends on if you have the button to upload and stuff BUT here is just the basics of it, since I don't know what your code is.
$fileupload = uploadedfilenamehere;
function grabLink() {
echo "site.com/".$fileupload;
}
Which would return:
"site.com/uploadedfilenamehere"
And if you need to have a directiory just change this:
echo "site.com/dir/".$fileupload;
Related
If I'm not being clear about anything let me know... I'm new to SO.
I'm having troubles getting Gmail to approve of my image URL that will activate my PHP script to track when people open my emails.
Gmail only allows me to "insert" photos that are specifically image files, such as png or jpg files. I have tried using a file-include mechanism:
http://www.example.com/?file=image.png with a two-line PHP script that includes the png file and then writes to a log all the tracking info. However, I have found this doesn't work since I'm technically referencing index.php in the URL.
I have also tried http://www.example.com/script.php where script.php would look like this:
<img src=image.png>
<?php
// write "Someone viewed your mail" in logs
?>
This doesn't work either because I'm still referencing a PHP file.
I'm using the Insert Photo > Web Address feature in Gmail... should I be inserting the file differently to fix my problem? I need to find a way to directly reference an image file on my server but also activate the PHP script.
Any ideas? Am I overlooking something obvious?
Figured out I can do this with Thunderbird:
Write --> Insert --> HTML
In the HTML box:
<img src="www.mysite.com/script.php">
Hopes this helps anyone who had my problem
So i have this one small thing im doing, and the thing is: It generates QRcodes using the google qrcode api. Id like to download the generated qr code with the press of a button into a /img folder i have inside the folder my php file is located at, and id need it to save with a numerical number which is the button's id. (it has like 120 buttons and each one has a 0-120 id, id like to save the qrcode that belongs to the button 10 with a name like 10.png) any ideas on how to do so?
__
Little edit: as Man Manam pointed out my question is: I have the image link, i want to save it in my server. Sorry for the confusion.
As you're using Google for creating the QR code, I assume you have a code like this somewhere:
$ga = new \Google\Authenticator\GoogleAuthenticator();
$qr_link = $ga->getUrl($username, $_SERVER['HTTP_HOST'], $secret);
// then you'd display that code with <img src="$qr_link">
What you need to do is to simply download that QR code instead of showing in browser. You can use curl for this or, even simpler, just fopen/file_get_contents if allow_url_fopen is set to ON in php.ini
$image_bin = file_get_contents($qr_link);
file_put_contents($target_file_on_filesyste, $image_bin);
So this is a weird phenomenon I've never experienced in that I have an HTML form on image upload (exactly the one on W3). It does it's job properly when clicked and pushes the user profile picture into a folder while saving the name of the file on a database. Underneath the upload, I have a little image tag that spits out the uploaded profile picture. The end goal is for that profile picture to be displayed on the page constantly while the session exists. When uploaded, it works perfectly fine and the profile picture appears. After one refresh, the image can't be found and the alt="blank" takes over. The location still stays proper in the database so I don't think that's the issue. Is there an error? Do I need to use JS onload? Does the image tag only work once? Please help and thank you for taking the time to read this.
PHP:
echo '<img src="'.$loaded_profile_picture.'"id="HOMEPROFILE" alt="blank" style="width:128px;height:128px">';
//$loaded_profile_picture has the value uploads/photo.jpg
Classes.php:
public function addProfilePicture(){
include_once "conn.php";
$sql=$dbh->prepare("UPDATE users SET UserProfilePicture=:UserProfilePicture WHERE UserName=:UserName;");
$sql->execute(array(
'UserProfilePicture'=>$this->getUserProfilePicture(),
'UserName'=>$_SESSION['UserName'],
));
}
Image Upload (Might be the culprit):
if($uploadsuccess&&move_uploaded_file($_FILES['fileToUpload']['tmp_name'], $target_file)){
echo " The file ".basename($_FILES['fileToUpload']['name'])." has been uploaded.";
$user->setUserProfilePicture($target_file);
$user->addProfilePicture();
if($user->getUserProfilePicture()!=NULL){
echo '<img src="'.$target_file. '" alt="nom">';
}
}
Edit:
While many users have a similar problem (i.e. Image display with <img src=""> not working) I have tried looking at localhost:8888/xampp/LocalPost/pages/uploads/photos.jpg and it displays just fine. I have also changed file permissions on Windows 7 with no luck. Thanks for all your hard work I'll keep searching.
Edit:
I got around the problem by using $_SESSION['UserProfilePicture'] and it sticks after a refresh. This doesn't solve the question. I'd still very much like someone to help me find what went wrong, because later on I would like to display other people's Profile Pictures which you obviously can't do with session variables.
first of all your missing } et the end of your script
if($uploadsuccess && move_uploaded_file($_FILES['fileToUpload']['tmp_name'], $target_file)){
echo " The file ".basename($_FILES['fileToUpload']['name'])." has been uploaded.";
$user->setUserProfilePicture($target_file);
$user->addProfilePicture();
if($user->getUserProfilePicture()!=NULL){
echo '<img src="'.$target_file. '" alt="nom">';
}
}
Check once that after refreshing your page you will be get the value of $loaded_profile_picture variable or not?
If you got the value of $loaded_profile_picture variable then check it is same as your previous path or not?
So this is simple to understand what i want to achieve. So i get links like theese:
http://rockdizfile.com/atfmzkm7236t
http://rockdizfile.com/xuj5oincoqmy
http://rockdizfile.com/pg8wg9ej3pou
So theese links are from one cloud storage site I want to make a php script that automates their downloading.
So I can't find which is the script or the thing these links download button starts and how can I start that so i can download it with php on my server?
Basically my idea is to download a lot of files but don't wanna do it manually so need automatic way of doing it. As far as I know I make a request which is the following 2 urls:
http://rockdizfile.com/pg8wg9ej3pou
http://wi32.rockdizfile.com/d/wsli6rbhfp4r2ge4t7cqeeztijrprelfiw4afvqg5iwspmvqabpkmgiz/Desislava%20feat.%20Mandi%20&%20Ustata%20-%20Pusni%20go%20pak%20(CDRIP).mp3
So the first url is executing the next one but here comes the tricky part as far as I tested that last string Desislava%20feat.%20Mandi%20&%20Ustata%20-%20Pusni%20go%20pak%20(CDRIP).mp3 is the file name we get when downloading so if you change it with for example somefile.mp3 it will download somefile.mp3 but with the same file content as http://wi32.rockdizfile.com/d/wsli6rbhfp4r2ge4t7cqeeztijrprelfiw4afvqg5iwspmvqabpkmgiz/Desislava%20feat.%20Mandi%20&%20Ustata%20-%20Pusni%20go%20pak%20(CDRIP).mp3 so the data is hidden in this hash wsli6rbhfp4r2ge4t7cqeeztijrprelfiw4afvqg5iwspmvqabpkmgiz or i think so. And now is the tricky part how to get this hash? we have almost everything we have the code for the url atfmzkm7236t the hash wsli6rbhfp4r2ge4t7cqeeztijrprelfiw4afvqg5iwspmvqabpkmgiz and the filename Desislava%20feat.%20Mandi%20&%20Ustata%20-%20Pusni%20go%20pak%20(CDRIP).mp3 There must be a way to download from this site without clicking so please help me kinda a hack this :)
you can use PHP's header function to force a file to download
header('Content-disposition: attachment; filename=index.php');
readfile('Link');
You should know that this will not give you the ability to download PHP files from external websites.
You can only use this if you got the direct link to a file
It's impossibly to tell you without the source code
e.g. sha1("Test Message") gives you 35ee8386410d41d14b3f779fc95f4695f4851682 but sha256("Vote this up") gives you 65e03c456bcc3d71dde6b28d441f5a933f6f0eaf6222e578612f2982759378ed
totally different... unless you're hidden function add's "65e03c456bcc3d71dde6b28dxxxxxxxxxxxxxxxxxxxxxxxxxx" (where xxxxxxxxxxxxxxxxxxxxxxxxxx is a bunch of numbers I can't be arsed to work out) to each hash...
then sha1("Test Message") gives you 65e03c456bcc3d71dde6b28d441f5a933f6f0eaf6222e578612f2982759378ed
The file is embedded into the swf player.
alert(jwplayer('mp3player').config.file);
Something like:
<?PHP echo file_get_contents($_GET["url"]); ?>
<script>
document.location=jwplayer('mp3player').config.file;
</script>
Though I've actually just noticed they change 5 digits of the URL on each page request, and the script above uses 2 page requests. One to get the URL and HTML source and another to try and download the file, meaning the URL has changed before the second request has started.
i have problem with uploading on my own server with nicEdit wysiwyg editor.
When you clikc on upload image you will upload image on other site. Here: imgur dot com
This is it: http://nicedit.com/demos.php
I want to use them php script to upload image on my own server/domain.
Can somebody tell me how to do it?
Here is the script: http://svn.nicedit.com//trunk/nicUpload/php/nicUpload.php
Still show message "Failed to upload image".
In console on firebug show this one:
<script>
try {
top.nicUploadButton.statusCb({"error":"Invalid Upload ID"});
} catch(e) { alert(e.message); }
</script>
POST is okay but i dont understand this. :(
Have anybody som good answer for me?
Thank you very buch.
PS: sorry for my english. :)
Daniel.
Did you install the PHP APC library on your server? I think you need to generate this id.
$id = $_POST['APC_UPLOAD_PROGRESS'];
NicEditor uses imgur as the default image upload service. The source code follows the API format described here: http://api.imgur.com/resources_anon#upload
My suggestion would be to implement the API request and response defined there.