Jump to content

form create new page


searls03

Recommended Posts

i don't know what this would fall under, but it sounds like php..........is there a way to make a form make a new page from a template........like I have a picture page and I can upload pictures from a form with a picture name....and that name turns into a /name.php file?  does this make sense?

Link to comment
Share on other sites

You mean something like this?

 

<?php
$template  = 'templates/pictures.php';
$picture = 'lolcat.png'; //this could be the uploaded picture

//we need just the filename - no extension
$picture_name = pathinfo($picture, PATHINFO_FILENAME);

copy($template, "templates/$picture_name.php");
?>

Link to comment
Share on other sites

ok I can explain what he wants

he wants to upload image from a form

then let's say the image name is 123.jpg

he wants to make page names 123.php immediately(automatic)

how can he do that??????????????

 

I already posted some code that can help him do that.

Link to comment
Share on other sites

ok I can explain what he wants

he wants to upload image from a form

then let's say the image name is 123.jpg

he wants to make page names 123.php immediately(automatic)

how can he do that?????????????? 

Thank God you arrived!!!  Without searl's translator I don't think we would ever understand.

Link to comment
Share on other sites

Sorry, I am nor really a describing type of person.  I like more to show, but can't really do that.  And thanks, I was just checking to see if that's what it does that you gave me. 

So has your questioned been solved?

Link to comment
Share on other sites

You mean something like this?

 

<?php
$template  = 'templates/pictures.php';
$picture = 'lolcat.png'; //this could be the uploaded picture

//we need just the filename - no extension
$picture_name = pathinfo($picture, PATHINFO_FILENAME);

copy($template, "templates/$picture_name.php");
?>

 

 

Instead of potentially creating hundreds of PHP files that essentially do the same thing, wouldn't it be better to store all the picture references in a database? Then just use templates/pictures.php page to display them all based on a id. That way if the initial template ever changes, you would only need to modify one file.

Link to comment
Share on other sites

so now I have it working....

<?php
$template  = 'Templates/index.php';
$picture = 'lolcat.png'; //this could be the uploaded picture

//we need just the filename - no extension
$picture_name = pathinfo($picture, PATHINFO_FILENAME);

copy($template, "$picture_name.php");
?>

 

how can I make it so that I can post certain pictures with this page that will show up?  I want to use a jquery object with this also.  how can I do this?  If it doesn't make sense let me know

Link to comment
Share on other sites

how can I make it so that I can post certain pictures with this page that will show up?  I want to use a jquery object with this also.  how can I do this?  If it doesn't make sense let me know

Makes no sense to me.

Link to comment
Share on other sites

one last question......how do I pull just the file extension from a picture name?  I want it to go where I have put 5 * at in the code.....I hope this makes sense.

 

$picture_name = pathinfo($picture, PATHINFO_FILENAME);
$sql = "INSERT INTO pictures (name, id, image,  event) 
	VALUES('$name', '$id','$image','$event')";
$rs = mysql_query($sql) or die ("Problem with the query: $sql<br>" . mysql_error());
	echo mysql_error();
}
copy($template, "$name.php");

?>
<form action="new.php" method="post" enctype="multipart/form-data"><input name="name" type="text" /><input name="id" type="hidden" value=<?php echo $id; ?> /><br />
<input name="event" type="text" /><input name="image" type="hidden" value="images/<?php echo $name; ?>*****" /><input name="submit" type="submit" value="submit" /></form>

Link to comment
Share on other sites

I'm sure there's a more efficient way, but you could get the extension by exploding the filename with the dot '.'

 

<?php

$file_parts = explode('.', $image);
$temp = count($file_parts) - 1;
$ext = $file_parts[$temp];

?>

 

 

Note there are some security issues to work on before going live.

 

First you want to look into dealing with visitors who pretend to upload an image, but are actually uploading something like a PHP script and naming it "image.php.jpg" or "ScriptToDoSomethingBad.php".

 

You'll also want to use mysql_real_escape_string() before saving the image name (and other information) to the database. Otherwise someone could modify/access you're database using SQL injections.

http://php.net/manual/en/function.mysql-real-escape-string.php

Link to comment
Share on other sites

I'm sure there's a more efficient way, but you could get the extension by exploding the filename with the dot '.'

 

<?php

$file_parts = explode('.', $image);
$temp = count($file_parts) - 1;
$ext = $file_parts[$temp];

?>

Or use pathinfo

$ext = pathinfo($image, PATHINFO_EXTENSION);

Link to comment
Share on other sites

  • 2 weeks later...

 

 

<?php
$template  = 'templates/pictures.php';
$picture = 'lolcat.png'; //this could be the uploaded picture

//we need just the filename - no extension
$picture_name = pathinfo($picture, PATHINFO_FILENAME);

copy($template, "templates/$picture_name.php");
?>

 

can I also use this to make directories?  if so, How??????

Link to comment
Share on other sites

so like this?

<?php
include_once "secure/connect_to_mysql.php";




$uploaddir = 'images/';
$id= $_GET['id'];
$event= $_GET['name123'] = str_replace(".", " ", trim($_GET['name123']));
$site = $_GET['site'].".php";
$template  = 'template.php';
$basic  = 'basic.php';
$standard  = 'standard.php';
$picture = '$event.png';
$target_path = "images/";

$file = $uploaddir . basename($_FILES['uploadfile']['name']); 
$size=$_FILES['uploadfile']['size'];
if($size>999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999)
{
echo "error file size > 1 MB";
unlink($_FILES['uploadfile']['tmp_name']);
exit;
}
if (move_uploaded_file($_FILES['uploadfile']['tmp_name'], $file)) { 
  echo "success";
  $sql = "INSERT INTO pictures(image, name, id, event, site) 
	VALUES('$file', '$file', '$id', '$event', '$site')";
$rs = mysql_query($sql) or die ("Problem with the query: $sql<br>" . mysql_error());
	echo mysql_error();

} else {
echo "error ".$_FILES['uploadfile']['error']." --- ".$_FILES['uploadfile']['tmp_name']." %%% ".$file."($size)";

$picture_name = pathinfo($picture, PATHINFO_FILENAME);


}
copy($template, "$site");
copy($basic, "basic$site");
copy($standard, "standard$site");
mkdir("/events/$event", 0700);


?>

Link to comment
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.