...

View Full Version : Uploading not working



Xaqa
08-27-2011, 02:55 AM
I have this code:


<form action="/index.php?page=site_add" method="post">
<table class="box">
<thead>
<tr>
<th colspan="2">Add Your Schematic</th>
</tr>
</thead>
<tbody>
<tr>
<td>Schematic Name:</td>
<td>
<input type="text" class="input" name="site_name" value="" />
<img src="/images/info.png" class="tooltip" title="The name of your schematic/build." />
</td>
</tr>
<tr>
<td>Your Schematic:</td>
<td>
<input name="site_url" type="file" />

<?php
$target = "schematics/";
$target = $target . basename( $_FILES['site_url']['name']) ;
$ok=1;
if(move_uploaded_file($_FILES['site_url']['tmp_name'], $target))
{
echo "The file ". basename( $_FILES['site_url']['name']). " has been uploaded";
}
?>
<img src="/images/info.png" class="tooltip" title="The Schematic of your uploading..." />
</td>
</tr>
<tr>
<td>Version:</td>
<td>
<input type="text" class="input" name="site_banner" value="" />
<img src="/images/info.png" class="tooltip" title="Include your schematic version." />
</td>
</tr>
<tr>
<td>Schematic Description:</td>
<td>
<textarea class="textarea" name="site_description"></textarea>
<img src="/images/info.png" class="tooltip" title="A detailed description of your schematic." />
</td>
</tr>
</tbody>
<tfoot>
<tr>
<td colspan="2"><input type="submit" name="submit" value="Upload Schematic" class="button" /></td>
</tr>
</tfoot>
</table>
</form>

Can you point out what's wrong? I'm uploading a file (.schematic) and it's not being uploaded.

Scyko
08-27-2011, 03:51 AM
I'm still a newbie to PHP but I can see one problem. In the <form> tag you need to include enctype="multipart/form-data" otherwise it wont accept files.

webdev1958
08-27-2011, 04:11 AM
also, if this is going onto a non local web server, some ISP's don't by default allow files to be uploaded. If pain persists, check with your ISP.

Xaqa
08-27-2011, 05:53 PM
Okay I got that to work, now what I want is the name of the file to be the value of the input so I'm trying to to do this:


<td>Your Schematic:</td>
<td>
<input name="site1" type="file" class="input" />


<?php
$target = "schematics/";
$target = $target . basename( $_FILES['site1']['name']) ;
$ok=1;
if(move_uploaded_file($_FILES['site1']['tmp_name'], $target))
{
echo "The file ". basename( $_FILES['site1']['name']). " has been uploaded";
}
?>
<input name="site_url" type="hidden" class="input" value="<?php echo basename( $_FILES['site1']['name']); ?>" />

But it's not working. Any thoughts?



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum