igpxnaruto4 Posted June 7, 2013 Share Posted June 7, 2013 so i have a pic editing website set up, and i have a function which lets you download images.http://jsfiddle.net/9Ytsk/ is what it looks like. what i want it to do is also generate the image to a different directory (gallery/gallery), and add +=1 if the image already exists (ex. image.png exists so it's named image1.png). Thanks! Link to comment Share on other sites More sharing options...
justsomeguy Posted June 7, 2013 Share Posted June 7, 2013 If you're talking about saving a canvas image on the server, there's a discussion about that here: http://stackoverflow...age-on-a-server Renaming would involve something like this, in PHP: $fname_orig = 'image.png';$fname = $fname_orig;$nr = 1;while (file_exists($fname)){ $chunks = explode('.', $fname_orig); $chunks[count($chunks) - 2] .= $nr++; $fname = implode('.', $chunks);} echo $fname; Link to comment Share on other sites More sharing options...
igpxnaruto4 Posted June 7, 2013 Author Share Posted June 7, 2013 i tried everything and i cant seem to get it to work. right now i have this set up - http://jsfiddle.net/9Ytsk/2/ i added that php part (does nothing on jsfiddle). and i forgot to mention on the main post that this is for a webpage which im using dreamweaver for (it doesn't display errors so i cant check the code). thanks Link to comment Share on other sites More sharing options...
justsomeguy Posted June 7, 2013 Share Posted June 7, 2013 It's going to work to run that on jsfiddle or Dreamweaver, you need an actual PHP web server. The PHP code is only half of it, you also need the ajax code to send the image data to PHP. That's how the image data gets from Javascript to PHP. PHP gets the image data from Javascript and creates a file on the server. Link to comment Share on other sites More sharing options...
igpxnaruto4 Posted June 9, 2013 Author Share Posted June 9, 2013 i really don't have much experience with this type of stuff. i was looking at var url = canvas.toDataURL("image/png;base64;"); downloadImage.attr('href', url); of the js and was wuondering if changing this (downloadImage.attr('href', url); ) in any way could possibly make it generate the file?like for example downloadImage.attr('./gallery/gallery', url);or url.copy('./gallery/gallery');Thanks Link to comment Share on other sites More sharing options...
justsomeguy Posted June 10, 2013 Share Posted June 10, 2013 This line: downloadImage.attr('href', url); Sets the "href" attribute of the downloadImage element to the given URL. The downloadImage element is a link on the page. So if the URL says "test", then that line is the same as doing this: <a class="downloadimage" href="test"> So it doesn't make sense to do this: downloadImage.attr('./gallery/gallery', url); which would be the same as this: <a class="downloadimage" ./gallery/gallery="test"> It doesn't mean anything to do that, it's not a valid attribute for a link. Javascript cannot save files. If you want to save a file you have to use something other than Javascript. Javascript can get the data you want to save, but it needs to send it to something like a PHP script which can actually save a file. Javascript just runs in your web browser, it can't save a file on the server. It can't do anything with the server except send requests to it. PHP runs on the server, it can save files there. Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now