sahanlak
asked on
URL parameter get disappear
I pass the id as an URL param, but when I submit the form id get disappearis there anyway to keep it when page get refresh ?
<?php
$_GET['id'];
$new_id = 'img'.$_GET['id'];
echo $new_id ;
$upload_errors = array(
UPLOAD_ERR_OK => "No errors.",
UPLOAD_ERR_INI_SIZE => "Larger than upload_max_filesize.",
UPLOAD_ERR_FORM_SIZE => "Larger than form MAX_FILE_SIZE.",
UPLOAD_ERR_PARTIAL => "Partial upload.",
UPLOAD_ERR_NO_FILE => "No file.",
UPLOAD_ERR_NO_TMP_DIR => "No temporary directory.",
UPLOAD_ERR_CANT_WRITE => "Can't write to disk.",
UPLOAD_ERR_EXTENSION => "File upload stopped by extension."
);
if(isset($_POST['subtrue'])==1){
if(isset($_POST['submit'])){
$a=($_FILES["file_upload"]);
$jpage= $a['type'];
$tmp_file=$_FILES['file_upload']['tmp_name'];
$target_file=basename($_FILES['file_upload']['name']);
$upload_dir='thumbs';
//if(move_uploaded_file($tmp_file,$uplaod_dir,'/'.$target_file))
if($jpage=='image/jpeg'||$jpage=='image/pjpeg'){
if(move_uploaded_file($tmp_file, $upload_dir."/"."$new_id.jpg")) {
medium($new_id);
$picview="$new_id.jpg";
$message="File uploaded successfully";
}//end move if
else{
$error = $_FILES['file_upload']['error'];
$message = $upload_errors[$error];
}//end else move
}//end of if jpeg
else{
$message="You can uplod only JPEG File ...";
}//end else Jpeg
}// end of post submit
}//end of !pho
else
{
$pho_error="Pleas Enter Photo Title";
}//end of else
?>
Ignore my last comment....
its for some other question...
Sorry of inconvenience caused.
its for some other question...
Sorry of inconvenience caused.
What do you mean disappears? Do you mean that when you do
$inputid = $_GET['id'];
echo $inputid;
that the echo shows nothing?
By the way, you should ALWAYS check ALL inputs for safety. For example, if id is an integer:
$inputid = floor($_GET["id"]); will ensure that it is an integer, and not some SQL Injection hacking.
Once you have a safe $inputid, then
$new_id = 'img'.$inputid;
echo $new_id ;
$inputid = $_GET['id'];
echo $inputid;
that the echo shows nothing?
By the way, you should ALWAYS check ALL inputs for safety. For example, if id is an integer:
$inputid = floor($_GET["id"]); will ensure that it is an integer, and not some SQL Injection hacking.
Once you have a safe $inputid, then
$new_id = 'img'.$inputid;
echo $new_id ;
ASKER
I call this page like this, upload.php?id=2 so when uploading I want the image to be renamed img2.jpg
So when I load the page :-
$_GET['id'];
$new_id = 'img'.$_GET['id'];
-------------
When I call the page upload.php?id=2 , $new_id = "img2". But when I hit the upload button the page gets refreshed and that time it's not calling any id so I'm getting only "img"
so all I want is to pass the id for $new_id whil page get refreshed.
See the complete code for the page
So when I load the page :-
$_GET['id'];
$new_id = 'img'.$_GET['id'];
-------------
When I call the page upload.php?id=2 , $new_id = "img2". But when I hit the upload button the page gets refreshed and that time it's not calling any id so I'm getting only "img"
so all I want is to pass the id for $new_id whil page get refreshed.
See the complete code for the page
<?php
$_GET['id'];
$new_id = 'img'.$_GET['id'];
echo $new_id ;
$upload_errors = array(
UPLOAD_ERR_OK => "No errors.",
UPLOAD_ERR_INI_SIZE => "Larger than upload_max_filesize.",
UPLOAD_ERR_FORM_SIZE => "Larger than form MAX_FILE_SIZE.",
UPLOAD_ERR_PARTIAL => "Partial upload.",
UPLOAD_ERR_NO_FILE => "No file.",
UPLOAD_ERR_NO_TMP_DIR => "No temporary directory.",
UPLOAD_ERR_CANT_WRITE => "Can't write to disk.",
UPLOAD_ERR_EXTENSION => "File upload stopped by extension."
);
if(isset($_POST['subtrue'])==1){
if(isset($_POST['submit'])){
$a=($_FILES["file_upload"]);
$jpage= $a['type'];
$tmp_file=$_FILES['file_upload']['tmp_name'];
$target_file=basename($_FILES['file_upload']['name']);
$upload_dir='thumbs';
//if(move_uploaded_file($tmp_file,$uplaod_dir,'/'.$target_file))
if($jpage=='image/jpeg'||$jpage=='image/pjpeg'){
if(move_uploaded_file($tmp_file, $upload_dir."/"."$new_id.jpg")) {
medium($new_id);
$picview="$new_id.jpg";
$message="File uploaded successfully";
}//end move if
else{
$error = $_FILES['file_upload']['error'];
$message = $upload_errors[$error];
}//end else move
}//end of if jpeg
else{
$message="You can uplod only JPEG File ...";
}//end else Jpeg
}// end of post submit
}//end of !pho
else
{
$pho_error="Pleas Enter Photo Title";
}//end of else
?>
<html>
<head>
</head>
<body>
<form action="upload.php" enctype="multipart/form-data" method="post">
<table>
<tr><td>Picture Upload
<input type="hidden" name="MAX_FILE_SIZE" value="1000000"></input>
<td><input type="file" name="file_upload"></input></td>
<input type="hidden" name="subtrue" value="1"></input></td>
<td><input type="submit" name="submit" value="Upload"></input></td>
</tr>
</table>
</form>
<?php if(!empty($message))
{
echo "<p> {$message} </p>";
}
?>
<?php
if(!empty($picview)){
echo " <img src='thumbs/medium/$picview'/>";
}
?>
</body>
</html>
<?php
function medium($new_id)
{
$img = 'thumbs/'.$new_id.'.jpg';
$canvas_width = 80;
$canvas_height = 80;
list($img_width, $img_height) = getimagesize($img);
$ratio_orig = $img_width / $img_height;
if($canvas_width / $canvas_height > $ratio_orig)
{
$canvas_width = $canvas_height * $ratio_orig;
}
else
{
$canvas_height = $canvas_width / $ratio_orig;
}
$original = imagecreatefromjpeg($img);
$canvas = imagecreatetruecolor($canvas_width, $canvas_height);
imagecopyresampled($canvas, $original, 0, 0, 0, 0, $canvas_width, $canvas_height, $img_width, $img_height);
if(imagejpeg($canvas, 'thumbs/medium/'.$new_id.'.jpg', 80))
{
return true ;
}
else
{
return false;
}
}
?>
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
@04it040
Hey man your awesome. I din't thought of that. Let me try it :)
Hey man your awesome. I din't thought of that. Let me try it :)
ASKER
Simple trick, worth more than the rating. Thanks again
Hi sahanlak,
Thanks for the points :)
Regards,
Abhinav
Thanks for the points :)
Regards,
Abhinav
This will give you a fair idea about the problem.
Open in new window