Jump to content

Recommended Posts

here is the PHP function I trying to make

<?php
function copy_image_file($source_db_file){
if (!copy($source_db_file, "images/sample.jpg")){
copy("product_img/noimage_large.jpg", "images/sample.jpg");
}
}
?>

now can you tell me what is wrong so my function is executed every time the page is loaded ?
Link to comment
https://forums.phpfreaks.com/topic/11129-about-php-functions/#findComment-41667
Share on other sites

PHP is executed before the final HTML is being sent to the user's browser. It's being executed on the server-side- your host or your computer.
Javascript is a client-side language, and that means it can be triggered by users click, when a user puts his mouse on something, when a user selects something etc'.

I dont know (but I dont think) Javascript can copy images, but you try and do something with php:
You said you want to copy an image to somewhere, when a user [b]clicks[/b] on a pic. So you can place a link to the pic, something like this (pay attention to bold part):
[b]<a href="copy.php?img=img1&ext=gif">[/b]<img src="img1.gif" border=0></a>
Now as you see, when the user clicks the image, he is directed to "copy.php" trasnfering data with the "GET" method (img=img1).
Now in copy.php, you can do this (your code):
[code]<?php
$img=$_GET['img'];
$img.=".";
$img.=$_GET['ext'];
if (!copy($img, "images/sample.jpg")){
copy("product_img/noimage_large.jpg", "images/sample.jpg");
}
?>[/code]

Then you can have link or a redirection to previous or other page.

Orio.
Link to comment
https://forums.phpfreaks.com/topic/11129-about-php-functions/#findComment-41692
Share on other sites

That is the only way Javascript can "call" a PHP script in line and continue to execute. It's really not that hard to do. Look at the Yahoo User Interface Library, specifically the [a href=\"http://developer.yahoo.com/yui/connection/\" target=\"_blank\"]Connection Manager[/a].

Ken
Link to comment
https://forums.phpfreaks.com/topic/11129-about-php-functions/#findComment-41715
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.