searls03 Posted May 25, 2011 Share Posted May 25, 2011 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? Quote Link to comment https://forums.phpfreaks.com/topic/237388-form-create-new-page/ Share on other sites More sharing options...
Fadion Posted May 25, 2011 Share Posted May 25, 2011 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"); ?> Quote Link to comment https://forums.phpfreaks.com/topic/237388-form-create-new-page/#findComment-1219926 Share on other sites More sharing options...
searls03 Posted May 25, 2011 Author Share Posted May 25, 2011 Will that create a new page from a form that people can enter the URL to see? And them the picture is on the page? I know the picture on page is a bit new thing I added here...... Quote Link to comment https://forums.phpfreaks.com/topic/237388-form-create-new-page/#findComment-1219986 Share on other sites More sharing options...
Fadion Posted May 25, 2011 Share Posted May 25, 2011 What you're asking isn't the clearest thing on earth, so please give some more detail. What are you trying to achieve? Quote Link to comment https://forums.phpfreaks.com/topic/237388-form-create-new-page/#findComment-1220065 Share on other sites More sharing options...
hemo-ali Posted May 25, 2011 Share Posted May 25, 2011 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?????????????? Quote Link to comment https://forums.phpfreaks.com/topic/237388-form-create-new-page/#findComment-1220080 Share on other sites More sharing options...
Fadion Posted May 25, 2011 Share Posted May 25, 2011 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. Quote Link to comment https://forums.phpfreaks.com/topic/237388-form-create-new-page/#findComment-1220084 Share on other sites More sharing options...
Maq Posted May 25, 2011 Share Posted May 25, 2011 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. Quote Link to comment https://forums.phpfreaks.com/topic/237388-form-create-new-page/#findComment-1220085 Share on other sites More sharing options...
searls03 Posted May 25, 2011 Author Share Posted May 25, 2011 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. Quote Link to comment https://forums.phpfreaks.com/topic/237388-form-create-new-page/#findComment-1220124 Share on other sites More sharing options...
Maq Posted May 25, 2011 Share Posted May 25, 2011 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? Quote Link to comment https://forums.phpfreaks.com/topic/237388-form-create-new-page/#findComment-1220133 Share on other sites More sharing options...
searls03 Posted May 25, 2011 Author Share Posted May 25, 2011 I don't want to mark it solved quite yet.... Am not at a computer where I can try the code right now. I want to make sure it works be fore I mark it as solved. Quote Link to comment https://forums.phpfreaks.com/topic/237388-form-create-new-page/#findComment-1220139 Share on other sites More sharing options...
searls03 Posted May 25, 2011 Author Share Posted May 25, 2011 ok, I want this to post to the main, public folder............ how do I do that? and how would it be that I could apply a dreamweaver template for the template? Quote Link to comment https://forums.phpfreaks.com/topic/237388-form-create-new-page/#findComment-1220149 Share on other sites More sharing options...
cyberRobot Posted May 25, 2011 Share Posted May 25, 2011 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. Quote Link to comment https://forums.phpfreaks.com/topic/237388-form-create-new-page/#findComment-1220150 Share on other sites More sharing options...
searls03 Posted May 25, 2011 Author Share Posted May 25, 2011 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 Quote Link to comment https://forums.phpfreaks.com/topic/237388-form-create-new-page/#findComment-1220153 Share on other sites More sharing options...
Maq Posted May 25, 2011 Share Posted May 25, 2011 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. Quote Link to comment https://forums.phpfreaks.com/topic/237388-form-create-new-page/#findComment-1220174 Share on other sites More sharing options...
searls03 Posted May 25, 2011 Author Share Posted May 25, 2011 never mind, I figured it out....... Quote Link to comment https://forums.phpfreaks.com/topic/237388-form-create-new-page/#findComment-1220176 Share on other sites More sharing options...
searls03 Posted May 25, 2011 Author Share Posted May 25, 2011 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> Quote Link to comment https://forums.phpfreaks.com/topic/237388-form-create-new-page/#findComment-1220184 Share on other sites More sharing options...
cyberRobot Posted May 25, 2011 Share Posted May 25, 2011 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 Quote Link to comment https://forums.phpfreaks.com/topic/237388-form-create-new-page/#findComment-1220192 Share on other sites More sharing options...
wildteen88 Posted May 26, 2011 Share Posted May 26, 2011 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); Quote Link to comment https://forums.phpfreaks.com/topic/237388-form-create-new-page/#findComment-1220695 Share on other sites More sharing options...
searls03 Posted June 3, 2011 Author Share Posted June 3, 2011 <?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?????? Quote Link to comment https://forums.phpfreaks.com/topic/237388-form-create-new-page/#findComment-1224808 Share on other sites More sharing options...
Fadion Posted June 3, 2011 Share Posted June 3, 2011 You can use mkdir to dynamically create directories. Keep in mind that you can't just use any name for files and directories. Different filesystems have specific rules on file/folder names and you have to clear those characters out. Here is a round-up on different systems (just a random google search). Quote Link to comment https://forums.phpfreaks.com/topic/237388-form-create-new-page/#findComment-1224884 Share on other sites More sharing options...
searls03 Posted June 4, 2011 Author Share Posted June 4, 2011 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); ?> Quote Link to comment https://forums.phpfreaks.com/topic/237388-form-create-new-page/#findComment-1225047 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.